/home/caleb/ASDV-Java/Semester 2/Assignments/lab6-Exceptions_CalebFontenot/src/main/java/com/mycompany/lab6/exceptions_calebfontenot/WriteWithAutoClose2.java |
nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt
nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java
package com.mycompany.lab6.exceptions_calebfontenot;
@author
public class WriteWithAutoClose2 {
public static void main(String[] args) {
try {
java.io.File file = new java.io.File("scores.txt");
if (file.exists()) {
System.out.println("File already exists!");
System.exit(0);
}
try (java.io.PrintWriter output = new java.io.PrintWriter(file);) {
output.print("John T Smith ");
output.println(90);
output.print("Eric K Jones ");
output.println(85);
}
} catch (Exception ex) {
System.err.println("Cought exception: " + ex);
}
}
}