假设我想编译Hello World程序。我使用通用的javac Hello_World.java。但是在cmd中,它显示"分号丢失"编译错误。
如何将此编译错误存储到文本文件中?甚至一个字符串也可以。我如何"赶上"这个错误?我的导师提出了类似的建议:
" javac filename.java 2> textfile.txt"
但我在网上找不到任何类似的东西。
答案 0 :(得分:0)
-verbose就是你要找的东西。它将显示编译器的日志,然后将输出放在文件中。
javac XXX -verbose> TextFile.txt的
答案 1 :(得分:-1)
做这样的事情
try{
//Some code
}catch(Exception e) {
System.out.println(e.toString); //printing the error to the console
saveToFile(e.toString); //creating a text file and storing the error data
}
public void saveToFile(String str) {
try {
File newTextFile = new File("C:/thetextfile.txt");
FileWriter fw = new FileWriter(newTextFile);
fw.write(str);
fw.close();
} catch (IOException iox) {
//do stuff with exception
iox.printStackTrace();
}
}