
package com.throwsss; import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream; /**
* IO异常 的处理
* @author Administrator
*用 throw new RuntimeException(e);方法
*/
class Read{
public static void readTest(){
File file = new File("D://aa.txt");
InputStream inputStream = null;
try {
inputStream = new FileInputStream(file);
byte[] bs = new byte[1024];
int length = 0;
while((length = inputStream.read(bs)) != -1){
String str = new String(bs,0,length);
System.out.println(str);
}
} catch (FileNotFoundException e) {
//e.printStackTrace();
throw new RuntimeException(e);
} catch (IOException e){
//e.printStackTrace();
throw new RuntimeException(e);
} finally{
if(inputStream != null){
try {
inputStream.close();
System.out.println("文件釋放成功");
} catch (IOException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
System.out.println("文件释放失败");
throw new RuntimeException(e); }
}
} }
}
public class Throwss { public static void main(String[] args) {
// TODO Auto-generated method stub Read read = new Read();
read.readTest();
} }