import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
public class test3 {
public static void main(String[] args) {
//write
try {
FileWriter fw = new FileWriter("C:\\Users\\Danny\\Desktop\\Credits.txt");
PrintWriter pw = new PrintWriter (fw);
pw.println("This is just some test data");
pw.close();
}
catch (IOException e){
System.out.println("Error!");
}
//read
try {
FileReader fr = new FileReader("C:\\Users\\Danny\\Desktop\\Credits.txt");
BufferedReader br = new BufferedReader (fr);
String str;
while ((str = br.readLine()) != null ) {
System.out.println(str + "\n");
}
br.close();
}
catch (IOException e){
System.out.println("File not found!");
}
}
}
This works but over writes the text file each time with the new input. How do I stop this over writing so that all information is stored in the file like an archive.