forked from damaohongtu/JavaInterview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBIOTest.java
More file actions
41 lines (38 loc) · 1.12 KB
/
BIOTest.java
File metadata and controls
41 lines (38 loc) · 1.12 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
package JavaDemo.IOTest;
import java.io.*;
/**
* @Author MaoTian
* @Classname BIOTest
* @Description 测试BIO的使用
* @Date 下午7:47 2019/8/7
* @Version 1.0
* @Created by mao<[email protected]>
*/
public class BIOTest{
public static void main(String[] args) throws IOException {
FileInputStream fis=null;
FileOutputStream fos=null;
try {
fis = new FileInputStream(new File("/home/mao/workspace/java/src/JavaDemo/IOTest/bio_in"));
fos = new FileOutputStream(new File("/home/mao/workspace/java/src/JavaDemo/IOTest/bio_out"));
int ch;
// 读取到结尾返回-1
while((ch=fis.read()) != -1){
System.out.println((char)ch);
fos.write(ch);
}
System.out.println(ch);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
if(null != fos){
fos.close();
}
if(null != fis){
fis.close();
}
}
}
}