dcsimg
!_NEWLINE_! is not working by the time of writing text into file ..
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   cdulla_cdulla
Posted On:   Tuesday, February 18, 2003 02:31 PM

Hi, I am reading each line from file and writing into another file ... It is writing continously in the file even if i use for new line ... Why " " is not working by the time writing text into file ... Here is my code: import java.io.*; import java.net.*; import java.util.*; public class Test11{ private BufferedReader data; private String line=null; private StringBuffer buf= new StringBuffer(); private BufferedWriter thewriter=null; private File file=null; private FileReader fr=null; private String inputL   More>>

Hi,


I am reading each line from file and writing into another file ...
It is writing continously in the file even if i use
for new line ...
Why "
" is not working by the time writing text into file ...


Here is my code:



import java.io.*;


import java.net.*;


import java.util.*;


public class Test11{



private BufferedReader data;


private String line=null;


private StringBuffer buf= new StringBuffer();


private BufferedWriter thewriter=null;


private File file=null;


private FileReader fr=null;


private String inputLocation="c:\test14.txt";



public Test11(){ }


public void disp(){


try {


file=new File(inputLocation);


fr = new FileReader(file);


data = new BufferedReader(fr);


while ((line = data.readLine()) != null) {


buf.append(line + "
");



}


String text=buf.toString();


thewriter = new BufferedWriter(new FileWriter("c:\test15.txt"));


thewriter.write(text);


buf=null;


thewriter.close();


} catch(IOException e) { System.out.println("error ==="+e ); }


}


public static void main(String[] args) {


Test11 t=new Test11();


t.disp();


System.out.println("all files are converted...");


}


}


I used "
" after reading each line .. i want output file also same as input file ... how do i break each line by the time writing into text file .. "
" is working in word pad but now working in notepad ... in note pad i am getting some thing like rectangle insted of "
" ....


Any help please .....


thanks.

   <<Less

Re: !_NEWLINE_! is not working by the time of writing text into file ..

Posted By:   AlessandroA_Garbagnati  
Posted On:   Tuesday, February 18, 2003 03:23 PM

Hi,

Instead of using the raw
, why don't you ask Java to give you the right separator for the OS you are running on, by using the System.getProperty("line.separator")?

Re: !_NEWLINE_! is not working by the time of writing text into file ..

Posted By:   Christopher_Koenigsberg  
Posted On:   Tuesday, February 18, 2003 02:38 PM

In files read by native applications on Unix-based systems (Linux, Solaris, etc.) a "newline" is denoted by, and recognized by, a single linefeed character, e.g. a "
" as you are writing.



In files read by native applications on MS DOS/Windows based systems, a newline is denoted/recognized by a pair, a "CRLF" (a carriage return "
", followed by a linefeed "
").



In files read by native applications on Macintosh MacOS (pre-OSX?) systems, a newline is a single carriage return character ("
").



Smarter applications nowadays (as you have found out, Wordpad AKA Word 6 does this, but not Notepad!) will be flexible, and recognize that they might be reading a file created for one of the other OS types, and hence might recognize more than one kind of newline convention.

About | Sitemap | Contact