未报告的异常java.io.FileNotFoundException;必须被抓住或宣布被扔6 [英] unreported exception java.io.FileNotFoundException; must be caught or declared to be thrown 6

查看:70
本文介绍了未报告的异常java.io.FileNotFoundException;必须被抓住或宣布被扔6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们继续运行此错误.目标是将数组中的数据读取到输出文件中.感谢您的帮助!

We keep running this error. The goal is to read the data from the array into an output file. Thanks for the help!

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

  }

推荐答案

由于出现已检查的异常. io.File%29"rel =" nofollow> FileOutputStream ,您没有捕获/throw-声明.

You are getting the error because there is a checked exception associated with FileOutputStream which you are not catching/throw-declaring.

这篇关于未报告的异常java.io.FileNotFoundException;必须被抓住或宣布被扔6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆