File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Reading in a file Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Reading in a file" Watch "Reading in a file" New topic
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
    
  13

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
    
  13

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.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Reading in a file
 
Similar Threads
problem with read() and readLine()
we ask for user input in c by writing & (ampersand) but how to achieve this in java ?
Problems w/ a HashMap
about toString method
socket not accepting data 2nd time