工作這是我寫刪除一個文件,如果它已經存在File.exists沒有在Java
public void createFile(Map<String, String> map, String name)
{
try
{
System.out.println("Creating new File...");
File file = new File("./Analysis/files/master.csv");
if (file.exists())
{
System.out.println("File Deleted...."+file.delete());
}
System.out.println("New File Created "+file.createNewFile());
FileWriter fw = new FileWriter(file, true);
for (Map.Entry<String, String> entry : map.entrySet())
{
fw.write(entry.getKey());
fw.write(",");
fw.write(entry.getValue());
fw.write("\n");
fw.flush();
}
fw.close();
}catch(IOException e)
{
throw new BuildException(e.getMessage());
}
}
這file.exists正顯示出它已存在於該路徑,以便文件錯誤代碼的不刪除該文件並將內容附加到該文件。任何想法?
該文件,如果不再存在已被刪除,你必須刷新更新內容的文件夾。 – 2013-12-13 15:08:56
您至少需要學習縮進代碼。 – kviiri
@nikpon你的觀點是什麼? – Freak