Mufleeh 0 Newbie Poster

Hi all,

I am in process of creating a simple polling system. I am using text files to store data. My question at this point is that I will be having a id number in a given .txt file.

I want to compare this number with what user input at the time of loggin in. I can read the data from the txt file using below code and wondering how to compare it with a text.

String fileName=getServletContext().getRealPath("admin.txt"); 

	File f=new File(fileName); 
	
	InputStream in = new FileInputStream(f); 
	BufferedInputStream bin = new BufferedInputStream(in); 
	DataInputStream din = new DataInputStream(bin); 
	 
	while(din.available()>0) 
	 { 
	out.print(din.readLine()); 
	 }

I've converted the input to a string as below,

String userId = request.getParameter("id");
 	session.setAttribute("idNum", userId); 

	String str = (String)session.getAttribute("idNum");

What all I've to do here is to compare the string 'str' with the string in text file. Can you make it to me?

my text file will contain just a single line string such as 78712A

Regards,
Mufleeh

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.