Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with IO

 
Peter Powers
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4567
8
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic