为简单起见,我有一个名为 FileEditor 的类:package modmaker;
import java.io.FileNotFoundException;
import java.util.*;
public class FileEditor {
public static Formatter projectFile;
public static String modName;
public void overWriteFile(){
try {
projectFile = new Formatter(modName+".txt");
System.out.println("Wrote project file");
} catch (FileNotFoundException e) {
System.out.println("Error writing project file");
}
}
public void addBlock(){
projectFile.format("blocks "+Blocks.blockName+" "+Blocks.blockDisplayName+" "+Blocks.doesEmitLight+" "+Blocks.lightValue+" "+Blocks.doesGenNaturally+" "+Blocks.genBelowLevel+" "+Blocks.genRariety+" "+Blocks.genClump+" "+Blocks.blockTexturePath);
projectFile.close();
}
}
当用户第一次进入程序时,会调用 overWriteFile 方法,制作文件。然后用户进入另一个窗口,在其中定义 block.* 变量,然后当调用按钮上的 actionPerformed 时,我希望调用 addBlock(),用当前变量格式化文件,但是当我尝试这样做时这多次,我给了我控制台错误......请帮助。