This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Help with IO Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help with IO" Watch "Help with IO" New topic
Author

Help with IO

Peter Powers
Greenhorn

Joined: Jan 10, 2013
Posts: 13
Hello,

When I run my code the output files are created but they are empty, suspect the problem is with my if statement - would appreciate any help/tips etc. Thanks in advance. Code below..


[Added code tags - see UseCodeTags for details]
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4339
    
    7

Hi Peter. Welcome to the Ranch!

I can see a couple of potential causes there.

1. Both your print statements just print a new line. Neither of them print anything else - I assume either the number or a message is supposed to be written?

2. You ought to close your PrintStreams. That's probably not the cause, but in some cases the stuff you print might be "buffered", and never get written if you never close the stream. It could lead to other problems as well. If you're using Java 7 the easiest way is to use a try-with-resources statement, which can automatically close resources for you. If you aren't, you should create the streams in a try block, and close them in a finally block. (If you haven't come across these, http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html is probably a good starting point).
 
wood burning stoves
 
subject: Help with IO
 
Similar Threads
Help with writing to a file!
I/O File problem.
Using percent Modulus to calculate total number of even numbers from user input
Exception error? Please help, frustrating
Help Help Help