aspose file tools*
The moose likes Beginning Java and the fly likes Help with java input file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help with java input file" Watch "Help with java input file" New topic
Author

Help with java input file

jonas okwara
Ranch Hand

Joined: Jun 22, 2004
Posts: 58
Please
I need help with this code. I want to be able to change "questionFile.txt" to correspond to the name of any file I input into the application.



try {

BufferedReader inputfile = new BufferedReader( new FileReader("questionFile.txt"));
for ( int i = 0; i < 3; i++){
question[i] = inputfile.readLine();
answer1[i] = inputfile.readLine();
answer2[i] = inputfile.readLine();
answer3[i] = inputfile.readLine();
answer4[i] = inputfile.readLine();
answer5[i] = inputfile.readLine();
}

inputfile.close();
}catch (IOException e) {
System.err.println(e);
System.exit(1);
}
Irina Goble
Ranch Hand

Joined: May 09, 2004
Posts: 91
jonas,

you are using the "FileReader(String fileName)" constructor in "new FileReader("questionFile.txt"))". So any string will do.
usha nataraj
Greenhorn

Joined: Jul 21, 2004
Posts: 6
jonas,
Pass the file name you want to read as Input parameter to main pgm like
> java pgmname "input file".
In your main function read it using args[0] into a string say strFile, where args[] is the main() function argument.
In BufferedReader constructor, you say -
BufferedReader br = new BufferedReader(strFile);
Hope this helps you out.


Thanks 'n Regards,<br />UshaRaju.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help with java input file