未报告的异常java.io.FileNotFoundException;必须被抓或宣布被抛出6

时间:2013-05-11 15:46:10

标签: java filenotfoundexception

我们一直在运行此错误。目标是将数组中的数据读入输出文件。谢谢你的帮助!

public static void save(Salesperson[] array)

  {
     PrintStream outfile = null;
     try
     {
        outfile = new PrintStream(new FileOutputStream("data.txt"));
     }
        catch(FileNotFoundException e)
        {
           JOptionPane.showMessageDialog(null,"The file could not be created.");
        }
         System.setOut(new PrintStream(new FileOutputStream("output.txt")));
     for(int k = 0; k < array.length; k++)
     {
        System.out.println(array[k]);
     }

     outfile.close();
     System.out.println("Saved.");

  }

1 个答案:

答案 0 :(得分:0)

您收到错误的原因是checked exceptionFileOutputStream相关联,您没有抓住/ throw - 声明。