package stuff;
import java.io.IOException;
public class DataWriter {
public static void main(String[] args) throws IOException {
java.io.File file = new j
your not closing the output variable
java.io.File file = new java.io.File("mydata.txt");
if(file.exists()) {
System.out.println("file already exists");
System.exit(1);
}
java.io.PrintWriter output = new java.io.PrintWriter(file);
output.println("data1");
output.println("data2");
output.println("data3");
output.println("data4");
output.println("data5");
output.println("data6");
output.println(" data7");
output.close(); //close<--------------------------------
System.out.println("data8");
You need to close the file with:
output.close();