如何将Java编译器错误捕获到文件中? [英] How can I capture Java compiler errors into a file?

查看:209
本文介绍了如何将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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆