IO操作基本步骤

package com.study02;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class IOtest03 {
public static void main(String[] args) {
File src = new File("abc.txt");
FileInputStream is = null;
try {
is = new FileInputStream(src);

for (int i = is.read(); i != -1; i=is.read()) {
System.out.print((char)i);
}

} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
if (is!=null) {
try {
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

}
}

猜你喜欢

转载自www.cnblogs.com/LuJunlong/p/11747642.html