wood burning stoves 2.0*
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
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: 4372
    
    8

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).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help with IO