java中让控制台输出彩色字符的方法-Jansi

在网上有很多类似的文章。教你如何在控制台输出彩色字符,其中比较好的方法是用别人的做好的包:Jansi。但是在网上很多的文章没有给出完整的操作过程。只是给出了方法,在这里将会有完整的过程。

1.      下载jnsi包

http://maven.outofmemory.cn/org.fusesource.jansi/jansi/1.11/

2.      将jar外部包导入

https://jingyan.baidu.com/article/fec7a1e5f79e2b1191b4e74f.html

3.  在代码中Import包

import static org.fusesource.jansi.Ansi.*;
mport static org.fusesource.jansi.Ansi.Color.*;

4.  使用下面的句子输出:

int i = 1 % 7;
System.out.print( ansi().eraseScreen().fg(RED).a(i).fg(YELLOW).a(" World").reset() );
System.out.print( ansi().eraseScreen().fg(RED).a(i).fg(GREEN).a(" World") );

--------------------- 本文来自 NEXTLJP 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/NEXTLJP/article/details/78709976?utm_source=copy

猜你喜欢

转载自blog.csdn.net/qq_36838191/article/details/82962680