Problem :
I want to create a simple program that will output a string to a text file. Below is my code :
import java.io.*;
public class JavaTesting {
public static void main(String[] args) {
File myfile = new File ("myfile.txt");
myfile.getParentFile().mkdirs();
PrintWriter printWriter = new PrintWriter(myfile);
printWriter.println ("Trying to write the txt using Java");
printWriter.close();
}
}
But J-grasp is throwing me the following error:
----jGRASP exec: javac -g JavaTesting.java
JavaTesting.java:10: error: unreported exception FileNotFoundException; must be caught or declared to be thrown
PrintWriter printWriter = new PrintWriter(myfile);
^
1 error
----jGRASP wedge2: exit code for process is 1.
As I am very new to Java, I am unable to understand the error. Can anybody help me in resolving the error?