1.11M Members

FileNotFoundException: Access is denied

 
0
 

I get this error when i write to my C drive using an ObjectOutputStream

List<String> strings = new ArrayList<String>();
		strings.add("test1");
		strings.add("test2");
		strings.add("test3");
		IO.IO.writeListToFile("C:\\Users\\coconnor\\Documents\\Java\\ToolKit\\", strings);
public static void writeListToFile(String location, List<?> list) {
		ObjectOutputStream p = null;
		File f = new File(location);
		try {
			p = new ObjectOutputStream(new FileOutputStream(f));
			p.writeObject(list);
			p.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

java.io.FileNotFoundException: C:\Users\coconnor\Documents\Java\ToolKit (Access is denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
at java.io.FileOutputStream.<init>(FileOutputStream.java:131)
at IO.IO.writeListToFile(IO.java:61)
at Testing.IOTest.<init>(IOTest.java:13)
at Testing.IOTest.main(IOTest.java:18)


Thanks in advance

 
0
 

java.io.FileNotFoundException

I think is says that The program can't find the file/path to the file.

Add a println() to show the value of location before the Constructor call to File().

 
0
 

oh lol, makes sense. I was trying to write a file to a directory instead of a file to a file. Thanks

Question Answered as of 4 Years Ago by NormR1
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article