import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
public class TestIO {
public static void main(String[] args) {
// 1、创建源
File src = new File("abc.txt");
// 2、选择流
InputStream is = null;
try {
is = new FileInputStream(src);
// 3、操作(读取)
int temp;
while ((temp = is.read()) != -1) {
System.out.println((char) temp);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
// 释放资源
try {
if (is != null) {
is.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
IO操作标准步骤
最新推荐文章于 2024-05-02 23:03:46 发布