第19天-20-IO流(改变标准输入输出设备)

static void setIn(InputStream in)   Reassigns the "standard" input stream.

static void setOut(PrintStream out)  Reassigns the "standard" output stream.

package bxd;

import java.io.*;

public class TransStreamDemo3 {
public static void main(String[] args) throws IOException { // 并不常用
System.setIn(new FileInputStream("s.txt"));
System.setOut(new PrintStream("out.txt")); BufferedReader bufr = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bufw = new BufferedWriter(new OutputStreamWriter(System.out)); String line;
while ((line = bufr.readLine()) != null) {
if ("eof".equals(line)) break;
bufw.write(line);
bufw.newLine();
bufw.flush();
}
bufr.close();
bufw.close();
}
}

第19天-21-IO流(异常的日志信息)

void printStackTrace(PrintStream s)  Prints this throwable and its backtrace to the specified print stream.

package bxd;

import java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.Date; public class ExceptionInfo {
public static void main(String[] args) {
try {
// 数组越界访问
int[] array = new int[2];
System.out.println(array[3]);
} catch (Exception e) {
PrintStream printStream = null;
String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
try {
printStream = new PrintStream("ExceptionInfo.txt");
printStream.println(time);
//printStream.write(time.getBytes());
} catch (Exception ex) {
throw new RuntimeException("日志文件创建失败");
}
e.printStackTrace(printStream);
} // 实际项目中会使用log4j.
}

第19天-22-IO流(打印系统信息)

static Properties getProperties()   Determines the current system properties.

package bxd;

import java.io.IOException;
import java.io.PrintStream;
import java.util.Properties; public class SystemInfo {
public static void main(String[] args) throws IOException {
Properties prop = System.getProperties();
prop.list(new PrintStream("Sysinfo.txt"));
}
}

毕向东_Java基础视频教程第19天_IO流(20~22)的更多相关文章

  1. 毕向东_Java基础视频教程第19天_IO流(01~05)

    第19天-01-IO流(BufferedWriter) 字符流的缓冲区 缓冲区的出现提高了对数据的读写效率. 对应类缓冲区要结合流才可以使用. BufferedWriter BufferedReade ...

  2. 毕向东_Java基础视频教程第19天_IO流(06~10)

    第19天-06-IO流(装饰设计模式) 装饰设计模式: 当想要对已有的对象进行功能增强时, 可以定义类,将已有对象传入,基于已有的功能,并提供加强功能.那么这个自定义的类称为装饰类. 装饰类通常会通过 ...

  3. 毕向东_Java基础视频教程第19天_IO流(11~14)

    第19天-11-IO流(字节流File读写操作) import java.io.FileInputStream; import java.io.FileOutputStream; import jav ...

  4. 毕向东_Java基础视频教程第19天_IO流(18~19)

    第19天-18-IO流(流操作规律 - 1) 通过三个步骤来明确"流操作"的规律: 明确数据流的"源和目的" 源, 输入流: InputStream/Reade ...

  5. 毕向东_Java基础视频教程第19天_IO流(15~17)

    第19天-15-IO流(读取键盘录入) InputStreamReader是字节流通向字符流的桥梁,它使用指定的charset读取字节并将其解码为字符.它使用的字符集可以由名称指定或显式给定,或者可以 ...

  6. 毕向东_Java基础视频教程第21天_IO流(1)

    第21天-01-IO流(对象的序列化) ObjectInputStream与ObjectOutputStream 被操作的对象需要实现Serializable接口(标记接口) 非必须, 但强烈建议所有 ...

  7. 毕向东_Java基础视频教程第20天_IO流(7~10)

    第20天-07-IO流(递归) package bxd; import java.io.File; public class FileDemo3 { // 非递归打印 public static vo ...

  8. Java基础知识_毕向东_Java基础视频教程笔记(19-21 IO流)

    18天-06-IO流 字节流和字符流 字节流两个基类:InputStream,FileInputStream,BufferedInputStream OutputStream,FileOutputSt ...

  9. Java基础知识_毕向东_Java基础视频教程笔记(22-25 GUI 网络编程 正则)

    22天-01-GUIGUI:Graphical User Interface 图形用户接口 Java为GUI提供的对象都存在java.Awt和javax.Swing两个包中CLI:Common lin ...

随机推荐

  1. Neo4j使用简单例子(转)

    Neo4j Versions Most of the examples on this page are written with Neo4j 2.0 in mind, so they skip th ...

  2. PowerDesigner16 生成的备注脚本,在sql server 2008 中报“对象名 'sysproperties' 无效”的错误的解决办法

    主要是在建模时我们对表.列增加了些说明注释,而Sql2005之后系统表sysproperties已废弃删除而改用sys.extended_properties所致. 1.修改Table TableCo ...

  3. android studio2.3.3 模拟器 Jni函数调用C++对象,lldb调试this指针和相关变量显示无效的原因

    android studio2.3.3 的版本中 Jni函数调用C++对象,对象调用相关的成员函数, lldb调试,变量跟踪窗口,this指针和相关变量显示无效的原因,但这些参数实际是有效的,只是de ...

  4. redis 集群的密码设置

    redis的密码设置有2种方式 1,  这个方法我没试 修改所有Redis集群中的redis.conf文件加入: masterauth passwd123 requirepass passwd123  ...

  5. java多线程---------java.util.concurrent并发包----------ThreadPoolExecutor

    ThreadPoolExecutor线程池 一.三个构造方法 ThreadPoolExecutor(int corePoolSize,int MaxmumPoolSize,long KeepAlive ...

  6. Prinzipien der Computer Zusammensetzung

    1.Die Einfuerung der Computer System 1.1 Computer Zusammensetzung und Computer Architektur Unter Com ...

  7. 行人检测4(LBP特征)

    参考原文: http://blog.csdn.net/zouxy09/article/details/7929531 http://www.cnblogs.com/dwdxdy/archive/201 ...

  8. [转]MongoDB 概念解析

    本文转自:http://www.runoob.com/mongodb/mongodb-databases-documents-collections.html 不管我们学习什么数据库都应该学习其中的基 ...

  9. SSIS教程:创建简单的ETL包 -- 3. 添加日志(Adding Logging)

    Microsoft Integration Services 包含日志记录功能,可通过提供任务和容器事件跟踪监控包执行情况以及进行故障排除. 日志记录功能非常灵活,可以在包级别或在包中的各个任务和容器 ...

  10. DataGridView 隔行显示不同的颜色

    两种方法 第一种 DataGridview1.Rows[i].DefultCellStyle.backcolor 第二种 AlternatingRowsDefutCellstyle 属性 获取或设置应 ...