how to append the data in a file
Dear All,
i want to continously update one text file that is
in myfile.txt using java,
for example username:test:password:test
like wise how can i append this text with username and password to added in the next next line
Create a FileWriter with the constructor shown below and then wrap it in a BufferedWriter.
http://java.sun.com/j2se/1.4.2/docs/api/java/io/FileWriter.html#FileWriter(java.lang.String,%20boolean)
See this for more details...
http://www.exampledepot.com/egs/java.nio/WriteBuffer.html
Message was edited by:
_helloWorld_
Hi,
Thanks For your Help.one thing i have to clarify,
while i am appending the file
it writes in straight line
(ie) username:test:password:test:
when i append the file, FileWriter writer =new FileWriter("/myfile.txt",true);
writer.write("test /n");
writer.write("test /n");
it adds in the same line.(ie) username:test:password:test:test:test
how can we add in the new line while appending the file
Take a look at this:
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
public class FileWrite {
public static void main(String[] args) throws IOException {
BufferedWriter br = new BufferedWriter(new FileWriter("C:\\temp.txt",true));
br.write("Hello");
br.newLine();
br.close();
}
}