毕向东_Java基础视频教程第19天_IO流(20~22)
第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)的更多相关文章
- 毕向东_Java基础视频教程第19天_IO流(01~05)
第19天-01-IO流(BufferedWriter) 字符流的缓冲区 缓冲区的出现提高了对数据的读写效率. 对应类缓冲区要结合流才可以使用. BufferedWriter BufferedReade ...
- 毕向东_Java基础视频教程第19天_IO流(06~10)
第19天-06-IO流(装饰设计模式) 装饰设计模式: 当想要对已有的对象进行功能增强时, 可以定义类,将已有对象传入,基于已有的功能,并提供加强功能.那么这个自定义的类称为装饰类. 装饰类通常会通过 ...
- 毕向东_Java基础视频教程第19天_IO流(11~14)
第19天-11-IO流(字节流File读写操作) import java.io.FileInputStream; import java.io.FileOutputStream; import jav ...
- 毕向东_Java基础视频教程第19天_IO流(18~19)
第19天-18-IO流(流操作规律 - 1) 通过三个步骤来明确"流操作"的规律: 明确数据流的"源和目的" 源, 输入流: InputStream/Reade ...
- 毕向东_Java基础视频教程第19天_IO流(15~17)
第19天-15-IO流(读取键盘录入) InputStreamReader是字节流通向字符流的桥梁,它使用指定的charset读取字节并将其解码为字符.它使用的字符集可以由名称指定或显式给定,或者可以 ...
- 毕向东_Java基础视频教程第21天_IO流(1)
第21天-01-IO流(对象的序列化) ObjectInputStream与ObjectOutputStream 被操作的对象需要实现Serializable接口(标记接口) 非必须, 但强烈建议所有 ...
- 毕向东_Java基础视频教程第20天_IO流(7~10)
第20天-07-IO流(递归) package bxd; import java.io.File; public class FileDemo3 { // 非递归打印 public static vo ...
- Java基础知识_毕向东_Java基础视频教程笔记(19-21 IO流)
18天-06-IO流 字节流和字符流 字节流两个基类:InputStream,FileInputStream,BufferedInputStream OutputStream,FileOutputSt ...
- Java基础知识_毕向东_Java基础视频教程笔记(22-25 GUI 网络编程 正则)
22天-01-GUIGUI:Graphical User Interface 图形用户接口 Java为GUI提供的对象都存在java.Awt和javax.Swing两个包中CLI:Common lin ...
随机推荐
- 基于nightmare的美团美食商家爬虫实践
前言美团商家页分析需要爬取的数据有(这里没有按人数爬)爬虫工具选取pysipderscrapynightmare同步任务js动态加载中断继续爬坑总结示例代码 前言 上学的时候自己写过一些爬虫代码,比较 ...
- 不依赖JQuery的入门Ajax代码
今天看了head first ajax这本书里ajax的实例,讲的很好,这本书觉着很不错,推荐下. Ajax (Asynchronous Javascript and XML)即异步Javascrip ...
- 【chrome】设置chrome允许WebGL从本地载入资源
找到chrome安装路径,然后创建一个快捷方式,右击该快捷方式,在 目标 输入框中加上-allow-file-access-from-files(前面加个空格),通过该快捷方式打开chrome就可以通 ...
- 安装TD出现Unknown user name or bad password问题
在Server 2003 sp2上安装TD8.0 出现Unknown user name or bad password,是因为2003启用了DEP保护. 关闭系统的DEP保护就可以了. 方法如下 ...
- ubuntu工具安装
smplayer sudo add-apt-repository ppa:rvm/smplayer sudo apt-get update sudo apt-get install smplayer ...
- linux mint 18.2 install erlang
由于Linux min 18.2仓库中的erlnag是18.2,我们手动安装最新版本,参考 https://www.erlang-solutions.com/resources/download.ht ...
- PHP之mb_substr_count使用
mb_substr_count (PHP 4 >= 4.3.0, PHP 5, PHP 7) mb_substr_count - Count the number of substring oc ...
- 利器推荐-Snipaste截图工具
利器推荐-Snipaste截图工具 一.引言 接触这个工具之前一直用QQ的ctrl+alt功能进行截图,但是有时候QQ没有登陆,或者没网的环境就没法使用:这时候可能会使用windows自带的截图工具, ...
- C#调用SQLite报错:无法加载 DLL“SQLite.Interop.dll”: 找不到指定的模块
C#调用SQLite数据库,有些情况下会报以下这个错误: 无法加载 DLL“SQLite.Interop.dll”: 找不到指定的模块 实际上程序目录中是存在SQLite.Interop.dll这个文 ...
- [PY3]——内置数据结构(3)——字符串及其常用操作
字符串及其常用操作xmind图 字符串的定义 1. 单引号/双引号 In [1]: s1='hello world' In [2]: s1="hello world" 2. 三对单 ...