• Post Reply Bookmark Topic Watch Topic
  • New Topic

File IO to absolute path  RSS feed

 
Greenhorn
Posts: 14
2
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

This has been driving me crazy...and I really need it to work. When I save my output to my workspace location it works perfectly fine. But when I try to save it to a different (absolute) location, the file is created, however its empty. I made a basic version to illustrate what I'm doing, so hopefully someone can see my dumb mistake easily ;)  First snipped of code works as intended. Second creates the right file at the right place, but is empty (saveMeString is the only difference in the two examples):






Of course the 'myFolder' actually exits. I'm guessing I'm missing something very trivial..but its been a few hours now and its driving me crazy
 
author & internet detective
Marshal
Posts: 37518
554
Eclipse IDE Java VI Editor
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chris,
Have a cow for a great question. I think your code is interfering with itself by trying to create the file after writing to it.

Note that if you are using Java 8, this whole thing can be done in two lines:


If you are still on Java 7, try moving the create earlier like this:



Also note that you should put the close in a try/finally block or in a try with resources.
 
Chris Sadowski
Greenhorn
Posts: 14
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gasp. Well, that was a perfectly logical and functional explanation   Thanks for the help, and the cow!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!