我正在编写一个“移至前面”编码器,它读取给定的文件,然后将文件解析为列表。它适用于编码,但它只适用于只有一行的文件,我认为问题出在 while 循环中。
这是代码:
while ((line = br.readLine()) !=
null) // While the line file is not empty after reading a line from teh text file split the line into strings
{
splitArray = line.split(" ");
}
for (int i = 0; i <= splitArray.length - 1;
i++) // for every string in the array test if it exists already then output data accordinly
{
if (FirstPass.contains(splitArray[i])) {
System.out.println(FirstPass.lastIndexOf(splitArray[i]));
FirstPass.addFirst(splitArray[i]);
FirstPass.removeLastOccurrence(splitArray[i]);
} else if (!FirstPass.contains(splitArray[i])) {
FirstPass.addFirst(splitArray[i]);
System.out.println("0 " + splitArray[i]);
}
}
System.out.println(" ");
for (String S : FirstPass) {
System.out.println(S);
}