0

I am using the CSVWriter from here

String csv_path = "C:\\output.csv";
CSVWriter csv_writer = new CSVWriter(new FileWriter(csv_path));
csv_writer.writeAll(data);
csv_writer.close();

But I encounter the common exception of Access is denied

java.io.FileNotFoundException: C:\output.csv (Access is denied)

I found an accepted answer here, but it seems cant solve my problem since I am using FileWriter.

You cannot open and read a directory, use the isFile() and isDirectory() methods to distinguish between files and folders. You can get the contents of folders using the list() and listFiles() methods (for filenames and Files respectively) you can also specify a filter that selects a subset of files listed.

I am using window 8. Is it something to do with the permission issue?

1
  • I seem to recall windowses not liking writing directly to root (unless you're admin). Try another directory instead (such as user's home dir). Commented Aug 27, 2014 at 16:20

4 Answers 4

2

The user running the java program probably does not have access to C:\

I would check the read/write permissions of the user under which you run the program. Alternatively, you can try a different dir not located at the root of your C drive.

Sign up to request clarification or add additional context in comments.

Comments

0

Run the eclipse as Administrator

Comments

0

Open Windows Explorer, under c: drive, right click your mouse to check whether there's option to create a file . You may compare the menu when you right click your mouse under other folder.

Comments

0

This happened to me when I inadvertently tried to open the parent directory with the FileWriter instead of the actual file. It's a common gotcha so I'll post this in case it reminds somebody else to check the obvious.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.