第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. [DPF] DB2 DPF 搭建实战

    1. Server 准备 2. NFS 系统设置 3. 创建实例 4. rsh/ssh 5. 测试 Server: 192.168.122.1  dpf01.dpf.com  dpf01 192.16 ...

  2. (转)[小工具] Linux下列格式化工具 - column

    当你看到Linux下命令输出的列歪歪扭扭时,是不是看着很不爽?column 命令就可以方便地解决这个问题. 比如: 我们一般就只用到上面这一个用法. column的其他用法如下: 选项 含义 -c 字 ...

  3. 【Ubuntu】安装配置apahce

    安装apachesudo apt-get install apache2 安装目录 /etc/apache2配置文件 /etc/apache2/apache2.conf默认网站根目录 /var/www ...

  4. 13.Reflect

    1.概述 Reflect对象与Proxy对象一样,也是 ES6 为了操作对象而提供的新 API.Reflect对象的设计目的有这样几个. (1) 将Object对象的一些明显属于语言内部的方法(比如O ...

  5. IO流(三)其他流与File类

    1:其他的流 1: DataOutputStream ;多了一些操作基本数据类型的功能 DataInputStream:读取文件. 用DataOutputStream流写进去的数据,就用DataInp ...

  6. python-thread多线程

    #!/usr/bin/python import threading,time def Music(): print "music is playing" time.sleep(3 ...

  7. R语言改变大小写 toupper()和 tolower()函数

    这些函数改变字符串的字符的大小写. 语法 toupper()和 tolower()函数的基本语法为: toupper(x) tolower(x) 以下是所使用的参数的说明: x - 向量输入. 示例 ...

  8. php 截取中文字符串方法

    /** * 截取中文字符串函数 * @param $str 需要截取的字串 * @param $start 开始截取的位置 * @param $length 截取的长度 * @return 此函数返回 ...

  9. Node.js模块封装及使用

    Node.js中也有一些功能的封装,类似C#的类库,封装成模块这样方便使用,安装之后用require()就能引入调用. 一.Node.js模块封装 1.创建一个名为censorify的文件夹 2.在c ...

  10. shell命令跟踪

    Linux Shell提供了两种方式来跟踪Shell脚本中的命令,以帮助我们准确的定位程序中存在的问题.下面的代码为第一种方式,该方式会将Shell脚本中所有被执行的命令打印到终端,并在命令前加&qu ...