package day09IoAndProperties;
import java.io.*;
public class TestIo {
public static void main(String[] args) throws FileNotFoundException {
//JDK 7 新特性 try(){...} catch {...} (不需要throws创建对象异常)
try( //创建输入流对象
FileInputStream fis = new FileInputStream("D:\\JavaForward\\a.txt");
//创建输出流对象
FileOutputStream fos = new FileOutputStream("D:\\JavaForward\\a.txt",true)){
fis.read();//调用方法读取内容
fos.write(97);//调用方法写入内容(写入的内容参照 ASCII + 系统码表)
}catch (IOException e) {
System.out.println(e);
}
//JDK 9 新特性 try(){...} catch{...} (需要throws创建对象异常)
//创建输入流对象
FileInputStream fis1 = new FileInputStream("D:\\JavaForward\\a.txt");
//创建输出流对象
FileOutputStream fos1 = new FileOutputStream("D:\\JavaForward\\a.txt",true);
try(fis1;fos1) {
fis1.read();
fos1.write(97);
}catch (IOException e) {
System.out.println(e);
}
}
}
JDK7和JDK9中关于文件流异常的新特性(重点)
最新推荐文章于 2024-11-04 20:33:37 发布