static class Variable{
public static File myfile;
public static String path = "E:\\java_file\\AccountData.txt";
Variable.myfile = new File(Variable.path);
}
当我尝试创建如下文件时:
protected static void FileCreate(){
try {
if (Variable.myfile.createNewFile())
System.out.println("File created");
else
System.out.println("File already exists");
} catch (Exception e) {
System.err.println(e);
}
}
出现错误:
令牌“ myfile”的语法错误,预计在之后出现VariableDeclaratorId 这个令牌
答案 0 :(得分:0)
更改为
public static String path = "E:\\java_file\\AccountData.txt";
public static File myfile = new File(path);