Friday, March 13, 2015

How to pass a filename to a program

The code below assumes that the filename to be used by the progam is contained in args[0]

public class FileNameDemo
{
    public static void main(String [] args) {
        String fileName = args[0];
        FileReader reader = new FileReader(fileName);
        Scanner inputFile = new Scanner(reader);
    }
   
}

No comments:

Post a Comment