2014-04-01 78 views
-2

我有2 File[]一個有2個完整文件(temp0temp1),一個有2個空的(tempOut0tempOut1)。但是,當我嘗試查看完整文件是否爲空時,它會查看所有文件。爪哇 - `文件[]`沒有做我會想到的

這是我做的陣列:

public msort(File[] tempInPut){ 
     int length = tempInPut.length; 
     this.inPut = new File[length]; 
     inPut = tempInPut.clone(); 
     System.err.println("test1 " + Arrays.toString(inPut)); 
     this.outPut1 = new File[length]; 


try{ 

    int i = 0; 
    while(i< inPut.length){ 
    outPut1[i] = new File(temp_dir + "//tempOut" + i + ".txt"); 
       outPut1[i].createNewFile(); 
    i++; 
    } 

這是他們獲得通過的合併:

public void merge(int outPutNum, File[] inPutArr, File[] outPut1) { 
    int index = 0; 
    while(index < inPutArr.length - 1) { 
     System.err.println("test1 " + Arrays.toString(inPutArr)); 
     if(inPutArr[index].exists() && inPutArr[index].length() == 0){ return; } 
     index++; 
    } 
} 

輸出:

TEST1 [/家庭/ tl113/317/temp0.txt,/home/tl113/317/temp1.txt]

test1 [/home/tl113/317/tempOut0.txt,/home/tl113/317/tempOut1.txt]

有誰知道爲什麼File[]outPut1File[]inPutArr結束了?

+0

這個問題似乎很容易用一些打印語句進行調試。 – keyser

+0

我一直在努力幾個小時,不能明白爲什麼。任何幫助將不勝感激。 – 1ftw1

+0

它看起來不像你正在做什麼與你的函數中的outPut1數組。你能再解釋一下你的意思嗎?你期望輸出什麼? – creechy

回答

1

有誰知道爲什麼我的File[] outPut1 ends up in my File [] inPutArr`?

因爲它已經存在,當你調用,當然這種方法。此方法對該參數不做任何操作。

我注意到你明顯調用了兩次不同的參數。你知道嗎?

注意這些詞是'輸入'和'輸出',而不是'inPut'和'outPut'。

0

它必須已經存在,因爲您不需要修改該數組。該方法只是拋出數組內容,所以你應該看看你的代碼中發生了什麼你不想要的。

編輯:

你確定你是路過的合併方法接收的參數正確的順序?什麼outPutNum合併?

+0

@Nick整個第一段構成了對該問題的答案。 – EJP

+0

如果您有新問題,請點擊[問問題](http://stackoverflow.com/questions/ask)按鈕。如果有助於提供上下文,請包含此問題的鏈接。 –

+0

@RomanC他沒有新的問題。他有一個關於*這個問題的問題,也有一個答案。他已經把它放在正確的地方。你的建議是徒勞的。 – EJP