File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help with IO" Watch "Help with IO" New topic

Help with IO

Peter Powers

Joined: Jan 10, 2013
Posts: 13

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

Joined: Apr 06, 2010
Posts: 4541

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, is probably a good starting point).
I agree. Here's the link:
subject: Help with IO
jQuery in Action, 3rd edition