很长一段时间以来,我一直为此拉头发.我研究了一个小时如何在 Java 中清除控制台.
I have been pulling my hair for this since quite long time. I have researched for an hour on how to clear a console in Java.
我发现的只是通过打印一堆行或执行这个来进行肮脏的黑客攻击
All I found was dirty hacking either by printing a bunch of lines or executing this
Runtime.getruntime.exec("cls/clear");
但是,似乎没有什么对我有用.真的没有任何方法可以像在 C (clrscr();) 中那样在 Java 中清除控制台.没有任何外部库可以实现这一点.
However, nothing seems to be working for me. Isn't there really any a way of clearing the console in Java like in C (clrscr();). Isn't there any external library by which this can be achieved.
如果有人在使用适当的函数、库等而不是肮脏的黑客攻击之前做过这件事,请告诉我.
Please let me know if anyone has ever done this before using a proper function, library etc. instead of dirty hacking.
如果您的终端支持 ANSI 转义码,这将清除屏幕并将光标移动到第一行第一列:
If your terminal supports ANSI escape codes, this clears the screen and moves the cursor to the first row, first column:
System.out.print(" 33[H 33[2J");
System.out.flush();
这适用于几乎所有的 UNIX 终端和终端仿真器.Windows cmd.exe 不解释 ANSI 转义码.
This works on almost all UNIX terminals and terminal emulators. The Windows cmd.exe does not interprete ANSI escape codes.
这篇关于如何在 Java 中清除控制台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
上传进度侦听器未触发(Google 驱动器 API)Upload progress listener not fired (Google drive API)(上传进度侦听器未触发(Google 驱动器 API))
使用 Google Drive SDK 将文件保存在特定文件夹中Save file in specific folder with Google Drive SDK(使用 Google Drive SDK 将文件保存在特定文件夹中)
Google Drive Android API - 无效的 DriveId 和 Null ResourcGoogle Drive Android API - Invalid DriveId and Null ResourceId(Google Drive Android API - 无效的 DriveId 和 Null ResourceId)
谷歌驱动api服务账户查看上传文件到谷歌驱动使Google drive api services account view uploaded files to google drive using java(谷歌驱动api服务账户查看上传文件到谷歌驱动使用java
Google Drive 服务帐号返回 403 usageLimitsGoogle Drive service account returns 403 usageLimits(Google Drive 服务帐号返回 403 usageLimits)
com.google.api.client.json.jackson.JacksonFactory;Google Drcom.google.api.client.json.jackson.JacksonFactory; missing in Google Drive example(com.google.api.client.json.jackson.JacksonFactory;Google Drive 示例