有时候我们有这样一种需求,我们需要进行长时间的IO读写。但是又是直接调用封装的方法。没办法打印日志,
我们希望可以在控制打印当前IO的读写状态。在不考虑读写性能的前提下,我的思路是:
/** * <per> * <p>控制台进度条</p> * <per/> * * @param * @return void * @throws * @Description * @author Liruilong * @Date 2020年08月19日 15:08:12 **/ public static void progress() { Thread thread = new Thread(() -> { StringBuilder tu = new StringBuilder("?"); while (true) { tu.append("?"); System.out.print("\r本地构建" + "Zip中:\t" + tu + "\t"); try { TimeUnit.MILLISECONDS.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } } }); thread.setDaemon(true); thread.start(); }
原文:https://www.cnblogs.com/liruilong/p/13533011.html