2017-10-05 69 views
0

我正在寫一個程序,我正在備份一堆基於包含路徑的文件的文件夾和文件。這個問題在我打開文件時到達,我一直在文檔中找到「我的音樂」。這個文件不存在我所能看到的。我通過CMD檢查,看了看其他地方,但它不斷出現。我試過file.exists,弄明白了,當我嘗試列出裏面的內容時,我得到nullPointer不存在。 `不存在的文件不斷出現

public static void enterFolder(String path, String runningPath) throws IOException { 
     //opens folder 
     File f = new File(path); 
     //check to see if folder exists I check in debug 
     boolean food = f.exists(); 
     //get an array of the stuff inside 
     File[] list = f.listFiles(); 
     DataOutputStream output; 
     DataInputStream input; 
     input = new DataInputStream(connection.getInputStream()); 
     output = new DataOutputStream(connection.getOutputStream()); 

     //loops through what is inside breaks here with nullPointer because list uninitialized 
     for (int i = 0; i < list.length; i++) { ` 

路徑是C:\用戶\ Tallennar \ Documents \我的音樂

runningPathC:\用戶\ Tallennar \ Documents \我的音樂

+0

所以'food'是'真',但'list'是'null'?這是什麼問題? –

+0

食物是真的,但我不能initalize列表,因爲f.listFiles()返回null –

+0

如果有I/O(或其他)錯誤,listFiles'也將返回null。試試'canRead'而不是'exists',看看你的程序是否真的能夠從該文件夾讀取。 –

回答

0

所以後經過大量研究後,我的音樂文件夾是Windows中的目錄連接點。這是爲了使XP程序與更新版本的Windows兼容。我的解決方案是刪除這些文件,因爲我個人沒有任何來自XP的程序。我如何刪除他們是我進入文件資源管理器的視圖選項卡中的選項。然後,我取消選中選項視圖選項卡中的隱藏系統文件。然後我突出顯示這些文件並刪除它們,並將選項設置恢復正​​常。

鏈接到XP路口信息: Phantom Folder Info