Command Line Parameters

home1 home2
 Bib
 Algorithms
 Bioinfo
 FP
 Logic
 MML
 Prog.Lang
and the
 Book

Prog'Lang'
 glossary
 Java

It's just like C -- see String[] argv below:

import java.lang.*;
import java.io.*;

public class CmdLine
 {
   public static void  main(String[] argv)
   { System.out.println("#--- CmdLine.java, L.A., CSSE, Monash, .au ---");

     for(int i=0; i < argv.length; i++) // command line params if any
        System.out.print("argv[" + i + "]=" + argv[i] + "\n");

     System.out.println("#--- end ---");
   }//main

 }//CmdLine class

// October 2002, L.Allison, CSSE, Monash University, .au

CmdLine.java lists its command-line parameters.

E.g. Cat someFile:

import java.io.*;

public class Cat
// Cat after cat as in conCATenate a file, try Unix: man cat
 {
   public static void  main(String[] argv)
   { System.out.println("#--- Cat.java, L.A., CSSE, Monash, .au ---");

     for(int i=0; i < argv.length; i++) // command line params if any
        System.out.print("# argv[" + i + "]=" + argv[i] + "\n");


     if( argv.length <= 0 )
        { System.out.println( "failed: no file given" );
          System.exit(1);
        }


     try{ File inputFile = new File( argv[0] );
          FileReader in  = new FileReader(inputFile);
          int c;
          while ((c = in.read()) != -1)       // read a character and
             System.out.print( (char) c );    // print it
        }
     catch(Exception e)
        { System.out.println( "failed: " + e.getMessage());
          System.exit(1);
        }


     System.out.println("#--- end ---");
   }//main

 }//Cat class

// October 2002, L.Allison, CSSE, Monash University, .au
// Released under GNU General Public Licence (GPL) ver.2, 1991.
// http://www.gnu.org/copyleft/gpl.html

java Cat someFile   copies the named file to standard output.

Coding Ockham's Razor, L. Allison, Springer

A Practical Introduction to Denotational Semantics, L. Allison, CUP

Linux
 Ubuntu
free op. sys.
OpenOffice
free office suite
The GIMP
~ free photoshop
Firefox
web browser

Java
 API

© L. Allison   http://www.allisons.org/ll/   (or as otherwise indicated),
Faculty of Information Technology (Clayton), Monash University, Australia 3800 (6/'05 was School of Computer Science and Software Engineering, Fac. Info. Tech., Monash University,
was Department of Computer Science, Fac. Comp. & Info. Tech., '89 was Department of Computer Science, Fac. Sci., '68-'71 was Department of Information Science, Fac. Sci.)
Created with "vi (Linux + Solaris)",  charset=iso-8859-1,  fetched Friday, 29-Mar-2024 08:57:40 AEDT.