• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

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

 
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:
 
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!!!
 
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!!!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!