没有捕获异常
用try ... catch ...
或者用个throw ,一般java书上都有建议用eclipse把,错误提示的很明显呢

解决方案 »

  1.   

    package studyproject;
    import java.io.*;
    /**
     * <p>Title: </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2004</p>
     * <p>Company: </p>
     * @author not attributable
     * @version 1.0
     */public class writeFile
    {
      public writeFile()
      {
      }
      public static void main(String[] args)
      {
        String aa = "d:\\aaa.txt";
        File my = new File(aa);
        PrintWriter pw = null;
        try
        {
          pw = new PrintWriter(new FileOutputStream(my));
        }
        catch (FileNotFoundException ex)
        {    }
        pw.println("我是中国人");
        pw.close();
      }}
      

  2.   

    是不是非要用try,catch块不可?在确信没有异常发生的地方也要用它么?
      

  3.   

    是不是规定:
    new PrintWriter
    语句必须用try,catch或者throw?
      

  4.   

    确切地说,是FileOutputStream的构造函数会抛出异常在java中,某个方法如果可能抛出异常(当然实际情况中可能有异常也可能没有),那么在使用这个方法时必须要处理这个可能的异常,用try,catch或者throw你可以查询jdk的api,每一个可能抛出异常的方法(包括构造函数)后面会有throws ...,并且下面都会有说明,比如你可以查FileOutputStream的构造函数,可以看到下面的说明:public FileOutputStream(File file)
                     throws FileNotFoundException
    Throws: 
    FileNotFoundException - if the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason 
    SecurityException - if a security manager exists and its checkWrite method denies write access to the file.