原谅我啥都不懂就好奇, 发现个好玩的东西
2016-01-03 16:49
411 查看
String shuru=""; BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in)); System.out.print("请输入内容:"); shuru=stdin.readLine(); System.out.println("你刚才输入的是"+shuru);
直接在输出的控制台上就可以输入内容, 后面用代码再读取出来
![](http://images2015.cnblogs.com/blog/816015/201601/816015-20160103164741479-370221679.png)
![](http://images2015.cnblogs.com/blog/816015/201601/816015-20160103164755167-1433202358.png)
还有读取某个位置的文本文档的代码
public static void readFileByLines(String str) { File file = new File(str); BufferedReader reader = null; try { System.out.println("以行为单位读取文件内容,一次读一行"); reader = new BufferedReader(new FileReader(file)); String tempString = null; int line = 1; //一次读一行,读入null时文件结束 while ((tempString = reader.readLine()) != null) { //把当前行号显示出来 System.out.println("line " + line + ": " + tempString); line++; } reader.close(); } catch (IOException e) { e.printStackTrace(); } finally { if (reader != null) { try { reader.close(); } catch (IOException e1) { } } } }
![](http://images2015.cnblogs.com/blog/816015/201601/816015-20160103171237948-1162489520.png)
![](http://images2015.cnblogs.com/blog/816015/201601/816015-20160103170836073-854711102.png)
相关文章推荐
- Markdown测试
- 详解Java编程的Observer观察者设计模式
- .net视频教程代码之《提交注册内容》
- 详解linux netstat输出的网络连接状态信息 【转】
- 【论文笔记】Unsupervised Discovery of Mid-Level Discriminative Patches
- 滴滴快车奖励政策,高峰奖励,翻倍奖励,按成交率,指派单数分级(1月3日)
- 《编写可读代码的艺术》读后总结
- Alpha、Beta、RC、GA的区别
- 【东臣PHP】HTML5
- hibernate 第一篇
- 四大组件---Service的生命周期(一)
- (Frontend Newbie)JavaScript基础之函数
- UVa1400
- 序列化与反序列化,并可通过transient实现序列化的优化
- 利用Intent 不同页面传递数据
- 职责链模式
- bootstrap实现弹窗和拖动效果
- openFileInput()和 openFileOutput()方法利用java流将数据存储到文件中
- 深度学习与计算机视觉系列(7)_神经网络数据预处理,正则化与损失函数
- C# 注释快捷