How do I pipe the Java console output to a file?

为君一笑 提交于 2019-11-28 06:54:34
Cedric Meury

Actually one can activate tracing in the Java Control Panel. This will pipe anything that ends up in the Java console in a tracing file.

The log files will end up in:

  • <user.home>/.java/deployment/log on Unix/Linux
  • <User Application Data Folder>\Sun\Java\Deployment\log on Windows
  • /~/Library/Caches/Java/log on OS X
oxbow_lakes

(If you can modify the code) you can set the System.out field to a different value:

System.setOut(new PrintStream(new FileOutputStream(fileName)));

If you are running a script (invoking the program via java) from Unix you could do:

/path/to/script.sh >& path/to/output.log
Jan Jirout

In Mac 10.8.2 logs could be found at /Users/<userName>/Library/Application Support/Oracle/Java/Deployment/log/.

Before you have to enable logging from Java Control Panel. Option "Enable logging" is at tab "Advanced". Java Control Panel could be started from "System preferences".

A frozen console probably means a deadlock (it could also mean repeated throwing of an exception). You can get a stack dump using jstack. jps may make finding the process easier.

try this guide it works for me. it also guides you that how you can set "System.setOut(fileStream);", "System.setErr(fileStream);"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!