尝试创建print方法时出现IOException

时间:2016-03-18 21:31:28

标签: java outputstream ioexception

public static void print()   {

    File location = new File("Hello.txt");
    String contents = "Hello World";
    OutputStream print = new FileOutputStream(location);
    print.write(contents.getBytes());
    print.close();
}

所以基本上尝试制作一段代码来创建一个文件并通过流写入hello world。

然而,每当我尝试编译时,我都会收到错误:

Generate.java:356: error: unreported exception FileNotFoundException; must be caught or declared to be thrown
    OutputStream print = new FileOutputStream(location);
                         ^
Generate.java:357: error: unreported exception IOException; must be caught or declared to be thrown
    print.write(contents.getBytes());
               ^
Generate.java:358: error: unreported exception IOException; must be caught or declared to be thrown
    print.close();
               ^
Note: Generate.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
3 errors

而且我无法抛出"抛出IOException"在方法之后,因为它不是主要方法

他们对此有所解决吗? 也有人知道底部的音符是什么意思吗?我总是通过某些程序获得它们,但即使我使用-Xlint重新编译它也似乎没有任何意义

0 个答案:

没有答案