Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

compare value from *.txt file  RSS feed

 
steve gan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to compare the value that inside *.txt file, how I can do it...
the content of *.txt just only time data, make a example:
8:00:00
9:00:00
hope every experts here can help me...thank
 
Michael Fitzmaurice
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Steve
When you say 'compare', what exactly do you mean? Do you just want to check whether or not the values are the same, or are you interested in determining by how much they differ if they are not the same? Do you need to do any time arithmetic? (I am assuming these values represent times).
Firstly, you need to read the 2 values in from the text file. Have a look at the API docs for the following classes in the java.io package:
- File
- FileReader
- BufferedReader
These will enable you to read the contents of the file into memory. From there, the equals & equalsIgnoreCase methods of the java.lang.String class will perform a simple equality check for you. If you need more than that, you could write some code to parse the times as integers and compare them that way.
Hope this helps
Michael
 
steve gan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank u, your assuming really help me....thank ^-^
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!