-
-
Save wbminsssss/78970ce9d3638d7892bcc6e1e39877f0 to your computer and use it in GitHub Desktop.
控制台输出一个进度条
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 控制台输出一个进度条 | |
| * 例如 测试 => [##################################################] 12/12 (100%) | |
| * | |
| * @param prefixStr 进度条前缀 | |
| * @param total 总进度 | |
| * @param current 当前进度 | |
| */ | |
| public static void consoleProgressBar(String prefixStr, int total, int current) { | |
| int percent = (int) ((double) current / total * 100); | |
| int filled = (int) Math.round(((double) current / total) * 50); | |
| String bar = "[" + "#".repeat(filled) + " ".repeat(50 - filled) + "] "; | |
| System.out.print("\r" + prefixStr + " => " + bar + current + "/" + total + " (" + percent + "%)"); | |
| if (current == total) { | |
| System.out.println(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment