| Author |
Reading in a file
|
Victoria Preston
Ranch Hand
Joined: Feb 03, 2006
Posts: 106
|
|
I have to read in a file that will be be given at run time but everytime i run the program it hangs. I mean it runs and runs and runs but is doing nothing. Here is the code.
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24057
|
|
As written, if the first argument is "-i", then you'll be prompted for input; but if it's not, then the program will read a line from the console without prompting. Is that what you intend? Is it "hanging" just because it's waiting for that one line? There can actually be some issues with data gettting "stuck" when you use BufferedReader with System.in. You always need to turn buffering off by using a 1-character buffer (I added text in bold): BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 1);
|
[Jess in Action][AskingGoodQuestions]
|
 |
Victoria Preston
Ranch Hand
Joined: Feb 03, 2006
Posts: 106
|
|
|
What it is suppose to do is read input from a file. Not of the screen in -i is not there. I just can't get it to read it.
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24057
|
|
|
But you don't open a file anywhere, do you? That would probably mean using a FileReader, and there's none to be found anywhere here.
|
 |
 |
|
|
subject: Reading in a file
|
|
|