java的Console类的使用方法及实例
作者:lqh 时间:2022-09-20 15:47:27
java的Console类的使用方法及实例
JDK 6中提供了java.io.Console类专用来访问基于字符的控制台设备。如果你的Java程序要与Windows下的cmd或者Linux下的Terminal交互,就可以用这个Java Console类代劳。
import java.io.Console;
import java.io.PrintWriter;
public class TestConsole {
public static void main(String[] args) {
Console cons = System.console();
if (cons != null) {
// -------------------------
PrintWriter printWriter = cons.writer();
printWriter.write("input:");
cons.flush();
// -------------------------
String str1 = cons.readLine();
// -------------------------
cons.format("%s", str1);
}
}
}
Java.io.Console 只能用在标准输入、输出流未被重定向的原始控制台中使用,在 Eclipse 或者其他 IDE 的控制台是用不了的。
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
来源:http://blog.csdn.net/aotian16/article/details/6588556
标签:java,Console
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
解决CollectionUtils.isNotEmpty()不存在的问题
2021-11-15 12:03:17
C# 16进制与字符串、字节数组之间的转换
2021-07-13 08:08:10
C#读写Config配置文件案例
2022-10-22 20:11:09
unity AudioSource播放完声音后要执行的函数或条件操作
2021-07-04 21:46:37
![](https://img.aspxhome.com/file/2023/0/104330_0s.jpg)
使用Logback日志保存到相对路径的操作
2021-10-11 16:42:30
android ItemTouchHelper实现可拖拽和侧滑的列表的示例代码
2023-08-14 14:51:51
![](https://img.aspxhome.com/file/2023/8/100588_0s.gif)
Unity3D实现导航效果
2022-09-26 02:15:54
![](https://img.aspxhome.com/file/2023/0/129700_0s.png)
JAVA 格式化日期、时间的方法
2023-10-17 07:53:22
基于Java实现经典蜘蛛纸牌游戏
2021-09-06 15:22:57
![](https://img.aspxhome.com/file/2023/8/79878_0s.png)
Android仿今日头条顶部导航栏效果的实例代码
2022-04-02 23:18:03
![](https://img.aspxhome.com/file/2023/7/139637_0s.png)
Android实现网易云音乐高仿版流程
2023-05-13 22:08:50
![](https://img.aspxhome.com/file/2023/2/92622_0s.png)
Java实现文件上传的两种方法(uploadify和Spring)
2022-10-06 03:59:28
java导出大批量(百万以上)数据的excel文件
2023-11-16 13:13:22
消息队列-kafka消费异常问题
2023-02-02 07:08:05
![](https://img.aspxhome.com/file/2023/4/118914_0s.jpg)
C#操作XML文件步骤
2021-11-04 21:51:44
![](https://img.aspxhome.com/file/2023/3/76433_0s.png)
C#反射之基础应用实例总结
2023-08-29 04:50:56
如何基于JavaFX开发桌面程序
2023-10-30 11:06:19
Java实现年兽大作战游戏详解
2023-11-08 04:28:05
![](https://img.aspxhome.com/file/2023/5/58875_0s.jpg)
2022 最新 IntelliJ IDEA 详细配置步骤演示(推荐)
2021-11-20 21:05:48
![](https://img.aspxhome.com/file/2023/3/77483_0s.jpg)
Java Collections.shuffle()方法案例详解
2023-11-24 15:53:16