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?

Community
  • 1
  • 1
jhyap
  • 3,779
  • 6
  • 27
  • 47
  • 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). – Kayaman Aug 27 '14 at 16:20

4 Answers4

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.

ltalhouarne
  • 4,586
  • 2
  • 22
  • 31
0

Run the eclipse as Administrator

jhyap
  • 3,779
  • 6
  • 27
  • 47
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.

peterpeng
  • 43
  • 5
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.

Glenn Lawrence
  • 2,844
  • 1
  • 32
  • 38