1
以下是iam用於刪除文件f1和將文件f2重命名爲f1的代碼。但它返回false。文件刪除和重命名問題
String strLine;
File f1 =new File("C:\\Equinox\\RootSipResource\\root\\root.properties");
File f2 =new File("C:\\Equinox\\RootSipResource\\root\\root1.properties");
FileInputStream fin = new FileInputStream(f1);
BufferedReader br = new BufferedReader(new InputStreamReader(fin,"UTF-8"));
OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(f2), "UTF-8");
while ((strLine = br.readLine()) != null) {
strLine = strLine.replace("root.label.43.2=PBS Kids"," root.label.43.2=PBS Kids NEW");
out.write(strLine);
out.write("\n");
}
out.flush();
out.close();
br.close();
//fin.close();
boolean delete= f1.delete();
boolean rename=f2.renameTo(f1);
System.out.println("delete----"+delete+ "rename-----"+rename);
我懷疑是因爲你打印錯誤的值!你應該打印'delete'而不是'f1.delete()',對於'rename'也是一樣的,注意這個操作有副作用! – amit