简体   繁体   中英

How to read read the contents of a text file in a separate Java package in a file

I have a package with a GUI, and in this GUI I need to read a text file (call it list.txt) that may look like

8:00am something

9:00am somethingelse

1:00pm something different

With each time/event on a separate line.

How do I read each line separately and extract the time portion from each line? What I need to accomplish is to compare times in a list like this to a range of times I have previously determined, and reprint the list with only events/times in that range, but I'm not sure on how to read it line by line.

How does the question not make sense? All I am asking is how to take a textFile (one written in a separate java package) and how to basically read it one line at a time and take the time portion from each line. The time is always at the start of each line. I'm sorry, but I don't know how to be more clear on that, that is about all there is to it.

And The user provides the text file name via GUI application, as well as a time range. But that part I have down.

  • Use java.io.BufferedReader 's readLine() method to read file line-by-line.
  • Use java.lang.String 's indexOf() method to locate the first space.
  • Use java.lang.String 's substring() method to extract before and after the space.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM