[英]System.out not working when calling jar-file from Windows command line
[英]System.out to Unix line endings on Windows
在Java中,新創建的輸出流查看系統行分隔符屬性以決定Unix和Windows行結尾,但是在程序啟動時已經創建了System.out,因此更改該屬性對該流沒有影響。
如果你想讓System.out
使用Unix行結尾,盡管在Windows上運行,除了避開println()
並總是使用print("...\\n")
嗎?
您可以手動設置System.out
。 我有時用它來將打印重定向到文件。
例如:
System.setOutput(new PrintStream("whatever_file.txt"));
在類似的意義上,您可以更改PrintStream
以考慮您的行結尾。
或者,您可以直接設置行結束字符的屬性:
System.setProperty("line.separator", "\n");
在通常的屬性設置器創建JVM時也可以這樣做:
java -jar bla.jar -Dline.seperator='\n'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.