I trying to write into the txt file.
But with out losing the data that is already stored in the file.
But my problem that when I put string in the txt file, the
You have to set the Stream to append mode like this:
pw = new PrintWriter(new FileWriter("d:\\stam\\stam.txt", true));
Use a FileWriter with second argument 'true' and a BufferedWriter:
FileWriter writer = new FileWriter("outFile.txt", true);
BufferedWriter out = new BufferedWriter(writer);
In Java 7,
Files.write(FileSystems.getDefault().getPath(targetDir,fileName),
strContent.getBytes(),StandardOpenOption.CREATE,StandardOpenOption.APPEND);
Create a separate variable to emphasize that, appending to file.
boolean append = true;
pw = new PrintWriter(new FileWriter(new File("filepath.txt"), append));