代码
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
public class IOTest01 {
public static void main(String[] args){
File src = new File("F:/myjava/IO_Study02/abc.txt");
InputStream is = null;
try{
is = new FileInputStream(src);
int temp;
while((temp = is.read()) != -1){
System.out.println((char)temp);
}
is.close();
}catch(FileNotFoundException e){
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}finally{
try{
if(null != is){
is.close();
}
}catch(IOException e){
e.printStackTrace();
}
}
}
}
步骤
- 创建源
- 选择流
- 操作(输入/输出)
- 释放资源