Java I/O文件程序
在以下代码中,有一个用于文件的基本I/O代码:
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws FileNotFoundException {
File file = new File("test.txt");
try {
PrintWriter output = new PrintWriter(file);
output.println("Testing");
output.println("123");
output.close();
} catch (IOException ex) {
System.out.printf("ERROR: %s!\n", ex);
}
try {
Scanner input = new Scanner( file );
String message1 = input.nextLine();
String message2 = input.nextLine();
System.out.println(message1);
System.out.println(message2);
} catch (FileNotFoundException ex) {
System.out.printf("ERROR: %s!\n", ex);
}}}}
现在,当我尝试运行它时,会出现以下错误:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at Main.main(Main.java:11)
你知道为什么会这样吗
# 1 楼答案
你有语法错误
有一个太多的紧密的卷发括号。取下最后一个紧密的卷发支架,你就可以开始了