我最近在高中的计算机科学课上学习了 Java,我正在努力学习的不仅仅是我在学校学到的基础知识。昨天,我设计了一个非常简单的文本编辑器,我命名为 Aqua,它是用 Swing 编写的。出于某种原因,当我运行这些方法时,我的计算机有点拖累。是因为我有一台糟糕的电脑还是我写错了什么?谢谢!
private void save(String content, String name) throws IOException{
System.out.println(dir.toString());
if(i<1){
dirCreation();
i++;
}
try{
String savedText;
savedText = content;
System.out.println(savedText);
File newTextFile;
newTextFile = new File(newDir.toString() + "\\" + name + ".aqua");
System.out.println(newDir.toString() + "\\" + name + ".aqua");
if (!newTextFile.exists()) {
System.out.println("Created new File");
newTextFile.createNewFile();
}
try (FileWriter fw = new FileWriter(newTextFile)) {
fw.write(savedText);
}
}
catch(IOException x){
System.err.format("IOException: %s%n", x);
}
}
private void load(String name) throws FileNotFoundException, IOException{
if(i<1){
dirCreation();
i++;
}
File loadingFile;
loadingFile = new File(newDir + "\\" + name + ".aqua");
Scanner scan = new Scanner(loadingFile);
String out = "";
while (scan.hasNextLine()) {
String line = scan.nextLine();
out+=line + "\n";
}
jTextArea1.setText(out);
}