public static void main(String[] args) {
        // try外面创建变量,提升变量的作用域
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream("E:\\迅雷下载");
            fos.write("我有一只小毛驴,我从来也不骑。".getBytes());
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException("文件写入失败,重试");
        } finally {
            try {
                if (fos != null) {
                    fos.close();
                }
            } catch (IOException e) {
                throw new RuntimeException("关闭资源失败");
            }
        }
    }

 

相关文章:

  • 2021-08-02
  • 2022-12-23
  • 2022-01-20
  • 2022-12-23
  • 2021-04-26
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-09
  • 2021-09-03
  • 2021-08-14
  • 2021-04-15
  • 2021-05-12
  • 2021-11-08
相关资源
相似解决方案