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

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().

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.