Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

read text file line by line and check for specific data

807603Oct 23 2007 — edited Oct 26 2007
Someone please correct my code so that my program reads the comma seperated text file line by line and

checks for a specific data(swf or image) in a 6th column and (Questions) in the 2nd column.

package readingFromTextFile;

import java.io.BufferedReader;
import java.io.FileReader;

public class MainClass 
{
	public static void main(String args[])
	{
		try 
		{
			FileReader fr=null;
			BufferedReader br = new BufferedReader(new FileReader("test.txt"));

			String s;
			while((s = br.readLine()) != null)
			{
				String[] tkn =s.split(",",-1);
				for(int i=0; i<tkn.length;i++)
				{
					System.out.println(tkn);
/*if(tkn[6]=="application/x-shockwave-flash")
{
System.out.println("SWF file found ");
}
if(tkn[6]=="image/jpeg")
{
System.out.println("Image file found ");
}
if(tkn[2]=="Questions")
{
System.out.println("Questions found");
}
else
{
System.out.println("Other type of slides found");
}*/

}
}
fr.close();
}
catch(Exception e)
{
System.out.println("Exception: " + e);
}
}
}
*the above code prints the output in the following format*
//Output:

AAAAA
1111111
2222222
http:test.html
application/x-url

222222
XXXXXXXXXX
Image
599204
483580
483579/media.jpg
image/jpeg

795
My file
Code
8
9
sample.swf
application/x-shockwave-flash

1296
stamps
New Polling
4863
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 23 2007
Added on Oct 23 2007
15 comments
258 views