To read specific texts from text files
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Albert_Leng
Posted On:   Thursday, February 7, 2002 01:52 PM

Hi there. I'm trying to make an application which reads from text file and use the data to load some images. What i'm trying to do is to read some lines like line 2 to line 4 or line5 to line 9... I tried to do using the following code but it doesnt work. It means the program just keep reading the same line (line 1) of the text file. Can anyone figure out how and tell me? Thanks a lot! try{ FileReader fR1 = new FileReader(file1); BufferedReader bR1 = new BufferedReader(fR1); line1 = bR1.readLine(); while(line1 != null) { if(0 < i&& i < 4){ tokenizer1 = new StringTokenizer(line1); endLeftName[i-1] = tokenizer1.nextToken(); System.out.p   More>>
			
Hi there.
I'm trying to make an application which reads from text file and use the data to load some images. What i'm trying to do is to read some lines like line 2 to line 4 or line5 to line 9... I tried to do using the following code but it doesnt work. It means the program just keep reading the same line (line 1) of the text file. Can anyone figure out how and tell me? Thanks a lot!
try{
FileReader fR1 = new FileReader(file1);
BufferedReader bR1 = new BufferedReader(fR1);

line1 = bR1.readLine();


while(line1 != null)
{

if(0 < i&& i < 4){
tokenizer1 = new StringTokenizer(line1);
endLeftName[i-1] = tokenizer1.nextToken();
System.out.println(i-1);
endLeft[i-1] = Toolkit.getDefaultToolkit().getImage(endLeftName[i-1]);//line 60
System.out.println(endLeftName[i-1]);
endLeftFName[i-1] = tokenizer1.nextToken();
endLeftF[i-1] = Toolkit.getDefaultToolkit().getImage(endLeftFName[i-1]);
endRightName[i-1] = tokenizer1.nextToken();
endRight[i-1] = Toolkit.getDefaultToolkit().getImage(endRightName[i-1]);
endRightFName[i-1] =tokenizer1.nextToken();
endRightF[i-1] = Toolkit.getDefaultToolkit().getImage(endRightFName[i-1]);
}
else if(4 < i && i < 10){
shortMidName[i-5] = tokenizer1.nextToken();
shortMid[i-5] = Toolkit.getDefaultToolkit().getImage(shortMidName[i-5]);
shortMidFName[i-5] = tokenizer1.nextToken();
shortMidF[i-5] = Toolkit.getDefaultToolkit().getImage(shortMidFName[i-5]);
}
line1 = bR1.readLine();
i++;

}

The other question is how can i parse a text file and when it meets a specific string, it will read the following lines? For example, let's say i have a text file like the following:
...
name:
Albert Daisy Kenny Alvin Bryan
...
That means when the application meets "name:", it will read the next lines...




Please use html tags to format code blocks.

   <<Less
About | Sitemap | Contact