如何将 Java 编译器错误捕获到文件中? [英] How can I capture Java compiler errors into a file?
本文介绍了如何将 Java 编译器错误捕获到文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我编译了一个Java程序
I compiled a Java program as
javac t1.java > a
为了将错误消息重定向到文件 a
.但是 a
没有错误内容(它们仍然出现在终端中).该命令是从 Linux 命令提示符执行的.
in order to redirect the error messages to file a
. But a
doesn't have the error contents (they still appear in the terminal). The command is executed from Linux command prompt.
t1.java 的内容如下:
The contents of t1.java is as:
class t1 {
public static void main(String[] args) {
System.out.printn("Hello World!"); // Display the string.
}
}
所以现在有一个错误,即println
被写成printn
.
So now there is an error, i.e. println
is written as printn
.
如何在文件 a
中捕获此错误消息?
How can I capture this error message in file a
?
推荐答案
尝试重定向 stderr
:
javac t1.java 2> error_file
这篇关于如何将 Java 编译器错误捕获到文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文