Results 1 to 11 of 11
Thread: Question about DataOutputStream
- 06-21-2011, 07:14 PM #1
- 06-21-2011, 07:20 PM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
You can have an underlying fileoutputstream which uses the append constructor, check the java 6 Apis.
- 06-21-2011, 07:21 PM #3
Look at the FileOutputStream's constructor. It has a parameter to append output to the end of the file.
- 06-21-2011, 07:40 PM #4
I get exception. I dont see how. First, I print these to a binary file:
Then I append a string the the end of the file in a new program, which I ran after the program above:PHP Code:String f = "ttest.txt"; FileOutputStream sout = new FileOutputStream (f); BufferedOutputStream poo = new BufferedOutputStream (sout); DataOutputStream fout = new DataOutputStream (poo); fout.writeInt (10); fout.writeInt (23215); fout.writeChar ('A'); fout.writeLong (60000950); fout.close (); sout.close (); poo.close ();
PHP Code:FileOutputStream sout = new FileOutputStream (f, true); BufferedOutputStream poo = new BufferedOutputStream (sout); DataOutputStream fout = new DataOutputStream (poo); fout.writeUTF ("hej"); //This string should be at the end of ttest.txt //Time to read all this: FileInputStream fi = new FileInputStream (f); BufferedInputStream foo = new BufferedInputStream (fi); DataInputStream fin = new DataInputStream (foo); System.out.println (fin.readInt ()); System.out.println (fin.readInt ()); System.out.println (fin.readChar ()); System.out.println (fin.readLong ()); System.out.println (fin.readUTF ()); //This should read the appended text(hej), but I get exception fin.close (); foo.close (); fi.close ();
- 06-21-2011, 07:44 PM #5
Please copy and paste here the full text of the error message.I get exception
Did you close the file before trying to read it?Last edited by Norm; 06-21-2011 at 07:46 PM.
- 06-21-2011, 09:48 PM #6
- 06-21-2011, 09:49 PM #7
Did you close the file before trying to read it?
- 06-21-2011, 09:53 PM #8
What do you mean by close the file? If you mean close the stream, then yes, I have
fout.close ();
sout.close ();
poo.close ();
btw its a runtime exception.Last edited by Pojahn_M; 06-21-2011 at 10:00 PM.
- 06-21-2011, 09:59 PM #9
What about after this:
fout.writeUTF ("hej"); //This string should be at the end of ttest.txt
- 06-21-2011, 10:04 PM #10
shit man, I cant believe I make mistakes like that!!!!
anyway, thanks. Works now.
- 06-22-2011, 09:52 AM #11
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Similar Threads
-
Dataoutputstream
By saranyabaskaran in forum New To JavaReplies: 6Last Post: 02-12-2011, 02:26 AM -
Question concerning question marks and colons
By jim01 in forum New To JavaReplies: 17Last Post: 01-14-2011, 12:05 AM -
Question mark colon operator question
By orchid in forum Advanced JavaReplies: 9Last Post: 12-19-2010, 08:49 AM -
How to use DataOutputStream and DataInputStream with PipedWriter and PipedReader
By Java Tip in forum java.ioReplies: 0Last Post: 06-26-2008, 07:34 PM -
File I/O with DataOutputStream
By Tzaphiel in forum New To JavaReplies: 0Last Post: 12-16-2007, 09:39 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks