Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Writing output to a file

 
aliya sharma
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I'm a beginner in Java. I'm creating a file so i can write my query results to it. This is what i'm doing:

when i run this : it always give a "could not create file". Could anyone please tell me what im doing wrong. THanks for your help.
Aliya
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks to me like you're trying to write to a path and not to a file.
 
aliya sharma
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, how do i write to a file?. I tried this:

Its still giving me could not create file
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by aliya sharma:
Its still giving me could not create file
The first thing to do is to display the actual exception. This will tell you why the file cannot be written. Perhaps the directory path doesn't exist or isn't writable by you.Once you know the error, we can help you go from there.
 
aliya sharma
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello David,
Its still giving me could not create file
The above is the code that i had in my catch method and which i had pasted as well.
Anywayz, i have figured out the problem. Thanks for your help , Jeff.

Aliya
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would you mind sharing your solution for posterities sake?

Layne
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by aliya sharma:
The above [ my code -DH ] is the code that i had in my catch method and which i had pasted as well.
No, the code you pasted did not include the output of the stack trace from the real exception. With the extra line I added, it would have displayed something likeBy catching IOException and tossing it away, you threw out the reason for the exception.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the I/O and Streams forum...
 
Switching from electric heat to a rocket mass heater reduces your carbon footprint as much as parking 7 cars. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!