Java-`File[]`并没有像我想的那样做

Java-`File[]`并没有像我想的那样做,java,arrays,Java,Arrays,我有2个文件[]一个有2个完整文件(temp0和temp1),一个有2个空文件(tempOut0和tempOut1)。但当我尝试查看完整文件是否为空时,它会查看所有文件 以下是我制作阵列的方法: public msort(File[] tempInPut){ int length = tempInPut.length; this.inPut = new File[length]; inPut = tempInPut.clone();

我有2个
文件[]
一个有2个完整文件(
temp0
temp1
),一个有2个空文件(
tempOut0
tempOut1
)。但当我尝试查看完整文件是否为空时,它会查看所有文件

以下是我制作阵列的方法:

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++;
    }
公共msort(文件[]tempInPut){ int length=tempInPut.length; this.inPut=新文件[长度]; inPut=tempInPut.clone(); System.err.println(“test1”+Arrays.toString(输入)); this.outPut1=新文件[长度]; 试一试{ int i=0; while(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++;
    }
}
public void合并(int-outPutNum,File[]inPutArr,File[]outPut1){
int指数=0;
while(索引
输出:

test1[/home/tl113/317/temp0.txt,/home/tl113/317/temp1.txt]

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

有人知道为什么
File[]
outPut1
会出现在
File[]
inPutArr
中吗

有人知道为什么我的
文件[]
outPut1
会出现在我的
文件[]inPutArr`

因为当你调用这个方法时,它已经存在了,当然,这个方法对这个参数没有任何作用

我注意到您显然使用不同的参数调用了该方法两次。您知道吗


注意:单词是“输入”和“输出”,而不是“输入”和“输出”。

它必须已经存在,因为您不需要修改该数组。该方法只是溢出了数组内容,因此您应该在代码中查看您不想看到的情况

编辑:


你确定你正在以正确的顺序传递merge方法接收的参数吗?outPutNum在merge上做什么?

这个问题似乎很容易用一些打印语句进行调试。我已经尝试了几个小时,不知道为什么。如果有任何帮助,我们将不胜感激。看起来你对outPut1 a没有做任何事情函数中有tempOut0.txt和tempOut1.txt,inPutArr中有tempOut0.txt和temp1.txtit@1ftw1不,不是。你自己的输出证明了这一点。@Nick整个第一段构成了问题的答案。如果你有新问题,请问我通过单击按钮。如果有助于提供上下文,请包含指向此问题的链接。@RomanC他没有新问题。他有关于此问题的问题,也有答案。他已将其张贴在正确的位置。你的建议是徒劳的。@EJP通常我在发布答案之前在评论中提问,如果我决定发布答案e答案我不会在帖子的正文中问任何问题,因为我可以在配额中标记原始问题。无论如何,这篇帖子已经过审核,我没有读原始问题。所以,我决定他问了这个问题?