Write to file using DataOutputStream
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Jojo_Angie
Posted On:   Tuesday, October 30, 2001 01:22 AM

How can do so that everytime I write to a file, the data will start in a new line. Below is part of the code from my program. String line; while(!(line =(String) in.readObject()).equalsIgnoreCase("QUIT")) { if(line.startsWith("CLIENT")) jTextArea1.append(" "+line); else { fout = new FileOutputStream("e:/num1.txt",true); dos = new DataOutputStream(fout); dos.writeBytes(line); dos.writeBytes(" "); } } and the example of data in source file are   More>>

How can do so that everytime I write to a file, the data will start in a new line. Below is part of the code from my program.


String line;

while(!(line =(String)
in.readObject()).equalsIgnoreCase("QUIT")) {


if(line.startsWith("CLIENT"))

jTextArea1.append("
"+line);


else {


fout = new FileOutputStream("e:/num1.txt",true);

dos = new DataOutputStream(fout);

dos.writeBytes(line);

dos.writeBytes("
"); }

}



and the example of data in source file are displayed as below:



12

-23

56

-99


Everytime when I write to the file, the integer will be written in this way:
12-2356-99


How can I do so that each time the data is written to the file, it will start on a new line that produce output like

12

-23

56

-99

   <<Less

Re: Write to file using DataOutputStream

Posted By:   John_Zukowski  
Posted On:   Tuesday, October 30, 2001 05:57 PM

If you are working with characters and lines, you shouldn't be using the Input/OutputStream objects. You should be using the Reader/Writer objects. Depending upon the platform you are on,
isn't what represents the end of line.
About | Sitemap | Contact