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此令牌
更改为
public static String path = "E:\\java_file\\AccountData.txt";
public static File myfile = new File(path);