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 \我的音樂
和runningPath
是C:\用戶\ Tallennar \ Documents \我的音樂
所以'food'是'真',但'list'是'null'?這是什麼問題? –
食物是真的,但我不能initalize列表,因爲f.listFiles()返回null –
如果有I/O(或其他)錯誤,listFiles'也將返回null。試試'canRead'而不是'exists',看看你的程序是否真的能夠從該文件夾讀取。 –