public void test() throws IOException{
try(
BufferedReader br=new BufferedReader(new FileReader("AutoCloseTest.java"));
PrintStream ps=new PrintStream(new FileOutputStream("a.txt"))
){
System.out.println(br.readLine());
ps.print("afdadffd");
}
}
当方法中出现throws时,调用应该使用try
catch去捕捉异常。如果不处理该异常,出现此类异常时,交给虚拟机处理。