• Post Reply Bookmark Topic Watch Topic
  • New Topic

No output written to a file using FileWriter  RSS feed

 
Shital Kapadia
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello:
FileWriter fw = new FileWriter("dnslookup.txt");
fw.write("apogent.com");
Can someone explain to me as to why the above 2 lines of codr don't work. What I mean by that is that nothing is written out to the file 'dnslookup.txt'. This is a very simple implmentation of a writer. What is it that I am missing out here in code, why does the above code not write anything to the file.
Thanks a lot,
Shital Kapadia
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you remember to flush?
 
John Holme
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shital, I'm having the same problem; did you ever find a solution? I've tried calling flush(), but to no avail
thanks,
John Holme
 
Nitin Parashar
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BufferedWriter fw= new BufferedWriter(new FileWriter("dnslookup.txt"));
fw.write("apogent.com");
Hope this helps
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote the following code:

If I type in "java TestFW Testing"
I get a file named testfw.dat, in the directory where this program resides, with the word "Testing" in it. If I create the FileWriter with a String versus a File, I get the same thing.
The same results occur if the file already exists or not.
It's pretty simple, are you still having problems?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!