Results 1 to 8 of 8
Thread: Writing to DAT or TXT file
- 10-11-2008, 08:33 AM #1
Member
- Join Date
- Oct 2008
- Posts
- 48
- Rep Power
- 0
Writing to DAT or TXT file
//------------------------------------------------------------------
...
String Username = "hunterbdb";
byte[] bite2 = new byte[100];
bite2 = username.getBytes();
FileOutputStream fos = new FileOutputStream
("C:\\Documents andSettings\\Administrator\\Desktop\\java projects\\notepads\\messenger_users.text", true);
fos.write(bite2,0,bite2.length);
...
//------------------------------------------------------------------
Hi, this is the code I'm using to write to a .txt file.
username is the String that I converted to bytes so that I can send through the FileoutputStream.
what i'm trying to do is append//add to the notepad file's text, however it is not working. Nothing is written to the file.
Am I doing something wrong?
Golden Brownies to the genius that helps me!Last edited by hunterbdb; 10-11-2008 at 08:38 AM.
-
Perhaps you wish to use a FileWriter which was built for writing text to text files.
- 10-11-2008, 02:58 PM #3
Does your code close the file after writing to it?
- 10-11-2008, 03:50 PM #4
Member
- Join Date
- Oct 2008
- Posts
- 48
- Rep Power
- 0
yea
yea, it closes the input output streams afterward
does Filewriter support abilities like "\n" to go to the next line and "\t" to tab?
- 10-11-2008, 04:37 PM #5
I copied your code, added a close() and it works for me. The file is created the first time and is added to after that.
What does this mean?it is not working. Nothing is written to the file.
What happens if you delete the file before the test? Is it created?
Is there anything in it?
What does the API doc say for FileWriter? It will write characters. \n and \t can be characters.Last edited by Norm; 10-11-2008 at 04:39 PM.
- 10-12-2008, 05:34 AM #6
Member
- Join Date
- Oct 2008
- Posts
- 48
- Rep Power
- 0
I used a filewriter like said above^
it works.
thanks! I didnt even know that filewriter existed.
- 10-12-2008, 01:42 PM #7
In general, try to stay with Writers for String data, but be aware that some file classes will not flush on close unless one places a close(); in the code as it is possible for the JVM to exit without writing all the data.
Best approach is to look through all the classes in java.io .... then do testing.Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
- 10-12-2008, 02:50 PM #8
Similar Threads
-
swapping the contents of the file and writing to another file
By Ms.Ranjan in forum New To JavaReplies: 9Last Post: 07-10-2008, 04:52 PM -
Writing to a file (at the end)
By Java Tip in forum Java TipReplies: 0Last Post: 02-08-2008, 09:22 AM -
Writing UTF to file using writeUTF
By Java Tip in forum Java TipReplies: 0Last Post: 01-22-2008, 08:19 PM -
writing to a file
By bugger in forum New To JavaReplies: 1Last Post: 11-11-2007, 02:49 AM -
Help with File reading and writing
By baltimore in forum New To JavaReplies: 1Last Post: 07-31-2007, 06:47 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks