抛异常分为两种方式,一种是抛出异常就处理异常就是所谓的try{}catch(){},还有一种就是IOException回避异常,就是在出现异常时不处理,在调用此方法时处理该异常,什么时候调用,什么时候处理异常。
import java.io.*;public class Ex6_2 { /** * @param args */ public static void main(String[] args)throws IOException{ // TODO Auto-generated method stub String fileName="D:/Hello.txt"; BufferedWriter out=new BufferedWriter(new FileWriter(fileName)); out.write("Hello!"); out.newLine(); out.write("This is another text file using BufferedWriter,"); out.newLine(); out.write("So I can use a common way to start a newline"); out.close(); }}
时间: 2024-10-13 22:20:50