자바 파일 읽기 질문입니다
해골
파일을 읽어서 그 파일안에 있는 특정값만 빼오기
test.txt 라는 파일이 있습니다
---------------------------------------------------------------------------------------------
ase
no id1 name
1 111 aaa
2 222 bbb
3 333 ccc
** abc 8.7.7 **
ase
no id2 name
4 444 aaa
5 555 bbb
6 666 ccc
end
asm
no id1 name
1 111 aaa
2 222 bbb
3 333 ccc
** abc 8.7.7 **
asm
no id2 name
4 444 aaa
5 555 bbb
6 666 ccc
end
asx
no id1 name
1 111 aaa
2 222 bbb
3 333 ccc
** abc 8.7.7 **
asx
no id2 name
4 444 aaa
5 555 bbb
6 666 ccc
end
-------------------------------------------------------------------------------------------------
이런 내용이 있습니다
file file = new file(test.txt);
filereader fr = null;
bufferedreader br = null;
string read = null;
arraylist list=new arraylist();
fr = new filereader(file);
br = new bufferedreader(fr);
while((read=br.readline())!=null)
{
if(read.indexof(asm)!=-1)
{
while((read=br.readline())!=null)
{
if(read.substring(2,3).equals(1))
{
system.out.println(read.substring(8,11));
list.add(read.substring(8,11));
if(read.indexof(end)!=-1
break;
}
}
}
}
첫번째 asm을 찾아
거기부터 다시 while로 읽습니다
그리고 읽은 라인에서 2,3번째가 1이면
그줄 8,11 번째를 리스트에 담습니다
다음엔 어떻게 해야 할지 모르겠습니다
그리고 저렇게 if 에 걸러서 다시 while로 읽는것도 이상하구요
계속 if while 로 건너뛸수도 없고
저파일에서 빨간색만 뽑아서 리스트에 담으려고 합니다
어떻게 해야 할까요?
그리고 indexof로 찾아서 그 문자가 있으면
몇줄 뛰워서 다음부터 읽게 하는 함수가 있나요?
그런 함수가 있다면 편할텐데