Unable to overwrite a hidden file in Java. When I attempt to with my code I get java.io.FileNotFoundException (Access is denied)
===

      private static boolean replaceUserPassword(String lineToBeReplaced, String replacementLine) {     
       try
        {
        File file = new File(defaultPath);
        Runtime.getRuntime().exec("attrib -H " + file.getCanonicalPath());
        System.out.println(file.isHidden());
        
        BufferedReader reader = new BufferedReader(new FileReader(file));
        String line = "", oldtext = "";
        while((line = reader.readLine()) != null)
            {
            oldtext += line + "\r\n";
            }
        reader.close();
        
        //To replaces line in defaultPath file
        String newtext = oldtext.replaceAll(lineToBeReplaced, replacementLine);
 
		file.setWritable(true);
		if(file.canWrite()){
			System.out.println("writing");
	        FileWriter writer = new FileWriter(defaultPath, false);
	        writer.write(newtext);
	        writer.close();
		}

		Runtime.getRuntime().exec("attrib +H " + file.getCanonicalPath());

      }
    catch (IOException ioe)
      {
        ioe.printStackTrace();
        return false;
      }
		return true;		
}


I don't have the file open in any other windows, and the process works when I unhide the file in the original folder.
Thank you for any future assistance.  