주어진 파일을 읽고 파일을 목록으로 구문 분석하는 "Move To Front"인코더를 작성했습니다. 그것은 인코딩과 함께 잘 작동하지만 단 한 줄의 파일에서만 작동합니다. 문제는 while 루프에 있다고 생각합니다. splitArray는 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);
}
죄송 BR은 버퍼링 독자 –
수정하시기 바랍니다 귀하의 게시물입니다 들여 쓰기를 수정하십시오. 탭을 적절한 수의 공백으로 바꾸십시오. –
첫 번째 while 루프는 전체 파일을 읽고 마지막 줄을 제외한 모든 데이터를 삭제합니다. –