Java编程思想:标准I/O
2024-10-02 02:18:38
import com.sun.xml.internal.ws.policy.privateutil.PolicyUtils; import java.io.*; public class Test { public static void main(String[] args) { // Echo.test(); // ChangeSystemOut.test(); Redirecting.test(); } } class Echo { public static void test() { BufferedReader stdin = new BufferedReader( new InputStreamReader(System.in)); try{ String s; while ((s = stdin.readLine()) != null&&s.length()!=0) { System.out.println(s); } } catch (IOException e) { //e.printStackTrace(); throw new RuntimeException(e); } } } class ChangeSystemOut { public static void test() { PrintWriter out = new PrintWriter(System.out,true); out.println("Hello, world"); // out.close(); } } class Redirecting{ public static void test() { try{ PrintStream console = System.out; //创建输入流,用于重定向输入 BufferedInputStream in = new BufferedInputStream( new FileInputStream("./src/Test.java")); //创建输出流,用于重定向输出 PrintStream out = new PrintStream( new FileOutputStream("./src/out")); System.setIn(in); System.setOut(out); System.setErr(out); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); try{ String str; while ((str = br.readLine()) != null) { System.out.println(str); } }finally { br.close(); out.close(); } System.setOut(console); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e){ e.printStackTrace(); } } }
最新文章
- 《疯狂Java讲义》(四)---- 面向对象&;基于对象
- HTML基础(2)
- Reprot中的五个Trigger说明
- 机器人与机器人仿真技术(zz)
- 专访CEO何朝曦:深信服高速成长的秘诀
- ssh environment variable
- JS-运动基础(一)
- cocos2d-x-2.2.6创建工程
- C#分布式事务解决方案-TransactionScope
- redis伪集群脚本
- Javascript高级编程学习笔记(27)—— BOM(1)window对象1
- V-rep学习笔记:切削
- 我们为什么要学习 Spring Boot
- Django的基本开发环境配置和MTV模型
- BATJ面试必会之Java IO 篇
- vuex的简单使用
- UVA-673 Parentheses Balance(栈)
- 679. 24 Game
- uwp获取版本信息win10 VersionInfo
- Xpath提取一个标签里的所有文本
热门文章
- GIS基础软件及操作(七)
- VS2015设置VS2017的“快速操作”快捷键Alt+Enter
- Java8 的一些新特性总结
- ThinkPHP 提供Auth 权限管理、支付宝、微信支付、阿里oss、友盟推送、融云即时通讯、云通讯短信、Email、Excel、PDF 等等
- mstsc也要使用/admin参数
- HTTPS上线过程说明(阿里云提供免费证书)
- “真正的工作不是说的天花乱坠”,Torvalds 说, “而是在于细节”(Torvalds 认为成功的项目都是99%的汗水和1%的创新)
- delphi 在多线程中使用 CreateOleObject 导致失败(一定要使用CoInitialize和CoUninitialize,举例查询WMI)
- jquery选择器集锦
- 【Linux】Linux 环境下splite以及一些正则使用