Results 1 to 3 of 3
Thread: FileWriter doesn't write
- 07-29-2009, 07:17 PM #1
Member
- Join Date
- Jul 2009
- Posts
- 2
- Rep Power
- 0
FileWriter doesn't write
Hi
I have this weird problem.
I'm using NetBeans and the code below does not work. Nothing gets written to my output file.
This is part of a large application I'm writing in NetBeans and really need this to work.Java Code:import java.io.File; import java.io.FileWriter; public class NewClass { public static void main ( String args[]){ try { File file = new File("myFile.txt"); FileWriter fileWriter = new FileWriter( file ); fileWriter.write( " test " ); } catch ( Exception e ){ e.printStackTrace(); } } }
Any ideas?
ThanksLast edited by superman5; 07-29-2009 at 07:20 PM. Reason: security
- 07-29-2009, 08:14 PM #2
Member
- Join Date
- Jul 2009
- Posts
- 2
- Rep Power
- 0
Actually I just checked and NetBeans is not the problem.
That code doesn't work anywhere.
Can someone tell me what the proper way to write to a text file is?
- 07-30-2009, 05:46 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Once you write something to FileWriter stream, until you flush them file is not updated.
Read the JavaDoc for more details on flush().Java Code:fileWriter.write( " test " ); fileWriter.flush();
Similar Threads
-
What are you using to write your code?
By CaptainMorgan in forum New To JavaReplies: 949Last Post: 05-28-2013, 12:27 AM -
JAva Filewriter
By tommyyyy in forum New To JavaReplies: 1Last Post: 03-28-2009, 12:51 PM -
scanner vs. BufferedReader? printstream vs. FileWriter?
By diggitydoggz in forum New To JavaReplies: 1Last Post: 01-09-2009, 01:58 AM -
How to write....**
By krichait in forum New To JavaReplies: 9Last Post: 08-07-2008, 02:09 PM -
New line or Carriage Return through FileWriter
By johnt in forum New To JavaReplies: 2Last Post: 05-20-2007, 09:13 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks