package io02;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
/**
- 理解操作步骤 (标准步骤)
- 1.创建源
- 2.选择流
- 3.操作
- 4.释放资源
- @author
*/
public class TestIO02 {
public static void main(String[] args) {
//创建源
File f = new File(“1.txt”);
//选择流
InputStream is = null;
try {
// InputStream is = new FileInputStream(f);
is = new FileInputStream(f);
//操作 (读取)
int temp;
while((temp = is.read()) != -1){
System.out.println((char)temp);
}
// int date1 = is.read();//第一个数据a
// int date2 = is.read();//第二个数据b
// int date3 = is.read();//第三个数据c
// int date4 = is.read();// 文件的末尾返回-1
//
// System.out.println((char)date1);
// System.out.println((char)date2);
// System.out.println((char)date3);
// System.out.println(date4);
// //释放资源
// is.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
//释放资源
try {
if(null != is){
is.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}