第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. 认识HTML5中的新标签与新属性

    前端之HTML5,CSS3(一) HTML5中常用内容标签 header标签 header标签定义文档的页眉,基本语法:<header>content</header>. na ...

  2. 代码版本控制:git使用

    1.https://github.com/ 注册账号 2. 点击 Start a project 3. 4. 5.      Clone or download 6.      安装git 7.    ...

  3. 剑指offer——面试题26:判断二叉树B是否为二叉树A的子结构

    #include"iostream" #include"stdio.h" #include"math.h" using namespace ...

  4. suse-Linux下安装Oracle11g服务器

    系统要求 Linux安装Oracle系统要求 系统要求 说明 内存 必须高于1G的物理内存 交换空间 一般为内存的2倍,例如:1G的内存可以设置swap 分区为3G大小 硬盘 5G以上 2.修改操作系 ...

  5. Array对象的判定

    /* 关于JS对象类型的判断,最复杂的在于RegExp和Array了,判定RegExp的情形不较少,而Array就比较多了,下面就是判断Array的方法 */ //方法一:利用instanceof来判 ...

  6. php 使用 rabbitmq

    1,配置好rabbitmq 服务器 (参照 http://www.cnblogs.com/spicy/p/7017603.html)(我是linux) 2,新增了一个用户 并点击该用户 增加权限如下

  7. Android多媒体技术之视频播放

    1.Android中视频播放方式 surfaceView+MediaPlayer,通过MediaPlayer来控制视频的播放.暂停.进度等: 使用VideoView 来播放,这个类其实也是继承了Sur ...

  8. 对Tensorflow中tensor的理解

    Tensor即张量,在tensorflow中所有的数据都通过张量流来传输,在看代码的时候,对张量的概念很不解,很容易和矩阵弄混,今天晚上查了点资料,并深入了解了一下,简单总结一下什么是张量的阶,以及张 ...

  9. hibernate与ibatis的区别

    Hibernate 是当前最流行的O/R mapping框架,当前版本是3.05.它出身于sf.net,现在已经成为Jboss的一部分了 iBATIS 是另外一种优秀的O/R mapping框架,当前 ...

  10. Solr后台管理

    Solr web管理后台 访问主页:http://localhost:8080/solr/#/ 1. Dashboard 仪表盘,显示Solr的基本信息,包含solr版本,包含系统内存和jvm内存的使 ...