Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading data from text file and comparing it with a string  RSS feed

 
Mufleeh Sadique
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.




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



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
 
Greg Charles
Sheriff
Posts: 3014
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a bit confused by that too. It's possible that Bear meant that comment for another thread. Anyway, no harm no foul, as the expression goes.

Is your only question how to compare two Strings? The String API is full of methods for that: equals, equalsIgnoreCase, startsWith, compareTo, and many others.
 
Greg Charles
Sheriff
Posts: 3014
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, my mistake. I read that as this question needed to move to the JSP forum.

Mufleeh, I agree with Bear that there's nothing about JSP here. Can you explain more clearly?

 
Mufleeh Sadique
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greg Charles wrote:Oh, my mistake. I read that as this question needed to move to the JSP forum.

Mufleeh, I agree with Bear that there's nothing about JSP here. Can you explain more clearly?



Hi Greg Charles,

Thanks for your reply. I believe this question is JSP I/O. Anyway my requirement is to write a script in JSP that reads data from a given text file and compare it with a user in put string. Did I say it clear enough Sir?


Regards,
Mufleeh
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that's clear. However apparently you still haven't realized that it doesn't matter that your code is in a JSP. Reading a file is reading a file no matter where the code is.

Anyway this thread already has code which reads lines of text from a file. That gives you a string each time you read a line. You compare two strings by using the equals() method. So just put that all together and there you have it. If there's something you still don't understand, go ahead and ask a specific question.

 
Mufleeh Sadique
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Yes, that's clear. However apparently you still haven't realized that it doesn't matter that your code is in a JSP. Reading a file is reading a file no matter where the code is.

Anyway this thread already has code which reads lines of text from a file. That gives you a string each time you read a line. You compare two strings by using the equals() method. So just put that all together and there you have it. If there's something you still don't understand, go ahead and ask a specific question.



Great, I got it and thank you!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!