-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrint.java
More file actions
44 lines (37 loc) · 1.21 KB
/
Copy pathPrint.java
File metadata and controls
44 lines (37 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package io;
/**
* Created by helmeter on 5/11/16.
*/
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
public class Print {
/**
* @param args
*/
public static void main(String[] args) {
// TODO自动生成的方法存根
char[] buffer=new char[512]; //一次取出的字节数大小,缓冲区大小
int numberRead=0;
FileReader reader=null; //读取字符文件的流
PrintWriter writer=null; //写字符到控制台的流
try {
reader=new FileReader("img/student.txt");
writer=new PrintWriter(System.out); //PrintWriter可以输出字符到文件,也可以输出到控制台
while ((numberRead=reader.read(buffer))!=-1) {
writer.write(buffer, 0, numberRead);
}
} catch (IOException e) {
// TODO自动生成的 catch 块
e.printStackTrace();
}finally{
try {
reader.close();
} catch (IOException e) {
// TODO自动生成的 catch 块
e.printStackTrace();
}
writer.close(); //这个不用抛异常
}
}
}