writing newlinw character to a file
import java.io.*;
class FileExample
{
publicstaticvoid main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new FileReader("C:/Documents and Settings/Admin/Desktop/emp name.txt"));
BufferedWriter out=new BufferedWriter(new FileWriter("C:/Documents and Settings/Admin/Desktop/Success.txt"));
String str;
while((str=br.readLine())!=null)
{
out.write(str+"\n");
}
out.close();
}
}
This program is to write contents of one file to another file. The file has ten strings. the problem is i am not able to insert newline character after the end of each string.
[1311 byte] By [
mikkua] at [2007-11-27 4:15:32]

Don't use readLine. That automatically removes the newline character.
Use a simple "read" and a simple "write" using FileInputStream and FileOutputStream.
FileInputStream fis = new FileInputStream(".....");
FileOutputStream fos = new FileOutputStream("...");
int b = 0;
while ((b = fis.read()) != -1) {
fos.write(b);
}
fis.close();
fos.close()
This, of course, does not include any error handling.
Edit: This is, of course, only one possible solution. You can also, of course, simply write a newline to the file after having written the line read, or add a newline to the line read before writing it to the file. The only thing is, of course, is that this "copy" routine should only be applied to text files, whereas the example posted here can be used on all file types.