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();
}
So basically Trying to make a piece of code that makes a file and writes hello world in it via streams.
However whenever I try to compile I get the error:
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
And I can't put "throws IOException" after the method since it's not a main method
Is their a fix to this? Also does anyone know what the notes at the bottom mean? I always get them with certain programs but it doesn't seem to mean anything even when I recompile with -Xlint