• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

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