JDK-6953475 : File.canWrite() returns false for User Folders
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 6u10
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_vista
  • CPU: x86
  • Submitted: 2010-05-18
  • Updated: 2012-08-03
  • Resolved: 2011-03-04
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
Java 1.6

ADDITIONAL OS VERSION INFORMATION :
Windows Vista Business Edition

A DESCRIPTION OF THE PROBLEM :
File.canWrite() always returns false for User folders such as Desktop, Contacts and so on.  This happens for both Admin and Limited User in widows Vista.


On a normal folder under C Drive it return true.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
File file = new File("C:\\Users\\Limited User\\Desktop");
System.out.println("Desktop can write : " +file.canWrite());

will print false

 file = new File("C:\\Users\\Limited User\\Desktop\\myfile.txt");
 System.out.println("File On  Desktop "+ file.canWrite());

will also print false

but if you continue to write the file, it will write the file myfile.txt on the desktop folder.
		
 file = new File("C:\\blah");
		System.out.println("Only folder can write : " +file.canWrite());
(folder does't exist from before) This will return true. which is correct as i want to create that folder.


		

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
should return false, to use "canWrite()" to display a application specific error message.
ACTUAL -
it always return false,

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public static void main(String[] args) throws IOException {
		
		File file = new File("C:\\Users\\Limited User\\Desktop");
		System.out.println("Only Desktop can write : " +file.canWrite());
		System.out.println("Only Desktop exist : " +file.exists());
		System.out.println("Only Desktop read : " +file.canRead());

		 file = new File("C:\\blah");
		System.out.println("Only blah can write : " +file.canWrite());
		System.out.println("Only blah exist : " +file.exists());
		System.out.println("Only blah read : " +file.canRead());

		
		
		 file = new File("C:\\Users\\Limited User\\Desktop\\myfile.txt");
		 System.out.println("File On  Desktop "+ file.canWrite());
		  Writer output = null;
		    
		 output = new BufferedWriter(new FileWriter(file));
		    output.write("file content");
		    output.close();
		    System.out.println("File written");
		    System.out.println("File can read "+ file.canRead());
		    System.out.println("File exist "+ file.exists());
			System.out.println("File On  Desktop "+ file.canWrite());
	}

---------- END SOURCE ----------

Comments
EVALUATION This seems to be a dup of 4939819.
16-08-2010