| 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: 75
|
|
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.
|
 |
 |
|
|
subject: Help with java input file
|
|
|