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;
}
我没有在任何其他窗口中打开该文件,当我取消隐藏原始文件夹中的文件时,该过程有效。感谢您对未来的任何帮助。