Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Want to write a combined text file, but nothing happens..

 
Sam Smoot
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trying to take 2 files and combine them into one (preliminary code... Want to do more with it, but can't get this to work... )...
Any help would be appreciated..
Output.txt should have all lines from both input files.... this is probably easy, I'm just "mentally challenged" at this point.. :roll:
Thanks!
Program code:

Input file 1:

Input file 2:
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sam,
I'm not really sure what the problem is. I couldn't immediately see a problem with the code, so I compiled it myself. Using the same inputs you used, this is my result:

This, as far as I can tell is the intended output. If this isn't what you're getting, perhaps it has something to do with a configuration issue. What version of Java are you using? I'm using Java 1.4.0.
If you were expecting something else, let me know and I can try to help you some more.
Corey
 
Sam Smoot
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yep, I get that with the system.out.println, but I need it to load the output.txt file with the same information (basically). Nothing gets written to the file....
UUURRRGGGHHHH!!! Brain Cramp!!!
 
Jonas Isberg
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would have tried putting an out.close() last in main, maybe also an out.flush() before the out.close(). This to make sure that the file is properly closed.
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by J Isberg:
I would have tried putting an out.close() last in main, maybe also an out.flush() before the out.close(). This to make sure that the file is properly closed.

Indeed - add the out.close() statement to the end and the output.txt file gets populated. Sorry I didn't understand what you wanted the first time.
 
Sam Smoot
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guess that's like closing the gate once you put the cows in... they won't stay if you don't...
That worked....
Thanks!!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic