尝试编译此代码时出现IOException错误:
public class TextEditor extends JDialog implements ActionListener {
public TextEditor (File fich,Frame owner) throws IOException{
super(owner,true);
fichier=fich;
String langage="//fortran_regex";
cree_ihm(langage);
};
public String config( String langage ) throws IOException {
BufferedReader reader = new BufferedReader(new FileReader (langage));
String line = null;
StringBuilder stringBuilder = new StringBuilder();
String ls = System.getProperty("line.separator");
try {
while( ( line = reader.readLine() ) != null ) {
stringBuilder.append( line );
stringBuilder.append( ls );
}
return stringBuilder.toString();
} finally {
reader.close();
}
}
private void cree_ihm(String langage) throws IOException{
config(langage);
}
}
///调用主时
import utils.TextEditor;
public class launch_editeur {
public static void main(String[] args) throws IOException{
TextEditor editeur=new TextEditor(null);
editeur.Affiche(true);
//editeur.setControlOn(false);
}
}
发生了什么事情?我用错了吗?我认为这可能与我调用的函数有关(或者可能与类有关?感谢
从您的评论中:
我得到这个: launch_editeur.java:5:错误:找不到符号公共静态 void main(String[] args) 抛出 IOException{ ^ 符号:类 IOException 位置:类 launch_editeur 1 错误
这与 IOException 错误(发生在运行时)不同,这是一个编译错误,表示它找不到类 IOException。您需要将 IOException 导入到使用它的类中:
import java.io.IOException;
finally
块中的reader.close()
调用需要尝试 { } 捕获它,因为它也可以抛出 IOException