Yes, I did attempt googling and searching through StackOverflow, however, I was unable to come up with an answer, as I am still new to Java.
Currently I am attempting to write data to a file, all I have as of now is:
private static void setup() throws IOException {
String username = System.getProperty("user.name");
File file = new File("C:\\Users\\" + username + "\\Documents\\", "data.txt");
if(!file.exists()) {
file.mkdir();
}
BufferedWriter out = new BufferedWriter(new FileWriter(file));
out.write("Bacon");
out.close();
}
However upon running the program, I receive an error regarding File Permissions, reading: Exception in thread "main" java.io.FileNotFoundException: C:\Users\cvi7\Documents\data.txt (Access is denied)
Now I see, java.io.FileNotFoundException
, however, how would I create the file if the new File()
doesn't? I am assuming it probably has to do with permissions however in the case my brain had a fail, I would hope to hear about this too.