Java 编译时发生IOException错误
我在尝试编译此代码时遇到IOException错误:Java 编译时发生IOException错误,java,ioexception,Java,Ioexception,我在尝试编译此代码时遇到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
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);
}
}
///////调用main时
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);
}
}
发生了什么事?
我用错了吗?我认为这可能与我调用的函数有关(或者可能与类有关?)
Thx读取器.close()调用最后
块需要一个try{}捕获,因为它还可以从您的注释中抛出IOException:
我得到以下信息:launch_editeur.java:5:错误:找不到符号public static void main(字符串[]args)抛出IOException{^symbol:类IOException位置:类launch_editeur 1错误
这与IOException错误(发生在运行时)不同,这是一个编译错误,表示找不到类IOException。您需要在使用它的类中导入IOException:
import java.io.IOException;
编译时出现此错误?我得到以下结果:launch_editeur.java:5:错误:找不到符号public static void main(字符串[]args)抛出IOException{^symbol:类IOException位置:类launch_editeur 1错误