Chandra Sekhar Chandra Sekhar - 1 year ago 274
Java Question

ioexception : a required privilege is not held by client while writing in file in java

I searched many of the similar questions, but could not solve my problem.

I am trying to write something in a file, which gives me error.

My code

try {
File f = new File(file_name);
FileWriter fstream = new FileWriter(f);
BufferedWriter out = new BufferedWriter(fstream);
ListIterator<String> itr = account.listIterator();//account is a List object
while (itr.hasNext()) {
String element =;

} catch (IOException e) {

The error is A required privilege is not held by the client
at Method)
at Source)
at com.example.Test.main(

This error arises only when
but when I change this
value to
C:\\New Folder\\Test.txt
New Folder
is a folder inside C Drive), then it works fine.

Why we are not able to create a file inside C Drive?

Answer Source

Since Windows Vista onwards, the default Windows set up does not allow users to create files in the root of the C: drive with standard privileges. If you need to create a file in a the root of a disk, you need admin rights and to run the app as administrator (or elevate to admin privileges some other way).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download