Java: File input in Class

overlord20

Gawd
Joined
Feb 5, 2010
Messages
623
I am trying to figure out how to do file input in a Class instead of main.

Code:
if ( args.length != 2 )
	{
		System.out.print("Enter input file name: ");
		infilename = scan.nextLine();
		System.out.print("Enter output file name: ");
		outfilename = scan.nextLine();
	}
else
{
	infilename = args[0];
	outfilename = args[1];
}

Used the above if statement above when I input the file into Main. But I want to do the file input in a Class now if it is even possible. I did a lot of searching and haven't found anything on the matter.

Help is appreciated.
 
Little confused what you are asking. Are you wondering how to pass the args array to your class?
 
I don't know if this helps or not but you could use this to open up a file chooser to select the file. But I'm not too sure if this is what you are looking for.

Code:
        JFileChooser FileBrowser;
        FileBrowser = new JFileChooser(); 
        int result = FileBrowser.showOpenDialog(null);
        if (result != JFileChooser.APPROVE_OPTION)
            return; 
        File filename = FileBrowser.getSelectedFile();
 
Back
Top