This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes I/O File problem. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "I/O File problem." Watch "I/O File problem." New topic
Author

I/O File problem.

prerna boja
Ranch Hand

Joined: Aug 19, 2004
Posts: 67
Hi all,

I have the following program, it shows no compiler error but my output is blank . I need to get the non negative numbers from SumNums.d1 file, which contains the data as :
12
34
-56
77
88
99
12
0
-2.

Is something wrong with my logic. If so please help me out.



Jeff Jetton
Ranch Hand

Joined: Mar 29, 2005
Posts: 71
Are you sure it compiles?

Take a look at the BufferedReader documentation and see if the read() method is really the best one to use for your purposes.

Oh, and there are logic errors in there too. First, what will happen to your while loop when your program reads in the zero on the second-to-last line of your input file? What if there were more non-negative numbers after that? (Or if the zero was the first number in your input file)

The rest of them you'll find pretty easily yourself when you get it to run.

Good luck!

- Jeff

[ April 13, 2005: Message edited by: Jeff Jetton ]
[ April 13, 2005: Message edited by: Jeff Jetton ]
Niki Nono
Ranch Hand

Joined: Mar 20, 2005
Posts: 256
why dont you create an algorithm for what you want to do?
This will make the logic pretty clear.
I think you should use the readLine() method to get each line and trim it before you put it inside a int variable.
think of sonething for the while loop and if you still face problems, do feel free to query.


Life called,so here I am.<br />Cheers<br />Niki.:-)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I/O File problem.