0

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

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.");

  }
4

1 回答 1

0

您收到错误是因为有一个已检查的异常FileOutputStream您没有捕获/声明相关联throw

于 2013-05-11T15:53:45.797 回答