简体   繁体   English

java在文本文件中以彩色打印

[英]java print in colour in text file

嗨,我有一个Java程序,我想知道如何在文本文件中打印该程序的结果而又不丢失它的颜色。我的意思是输出是彩色的,我希望得到colourfull的打印结果。

You can't. 你不能

Plain text is just that. 纯文本就是这样。 There is no formatting in a plain text file that lets you specify color/font/size. 纯文本文件中没有格式可用于指定颜色/字体/大小。

However, if you are displaying the text in a Bash shell or have configured your windows command console correctly, you could use ANSI Escape Codes to format the text. 但是,如果要在Bash Shell中显示文本或已正确配置Windows命令控制台,则可以使用ANSI转义码格式化文本。

You can't. 你不能 Textfiles don't have colors. 文本文件没有颜色。

You could wrap them in HTML tags and style them with css. 您可以将它们包装在HTML标记中,并使用CSS设置样式。 (there are probably libaries that do that for you). (可能有一些库可以为您做到这一点)。 This HTML file can be viewed with a webbrowser. 可以使用Web浏览器查看此HTML文件。

You could also use ANSI escape code to format your text (eg https://github.com/fusesource/jansi ) 您还可以使用ANSI转义代码来设置文本格式(例如https://github.com/fusesource/jansi

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM