Results 1 to 4 of 4
- 06-26-2011, 06:29 AM #1
Member
- Join Date
- Nov 2010
- Posts
- 9
- Rep Power
- 0
Is there a way to read a specific line in a txt file (without iterating through)?
Obviously I could just iterate through lines until I get to the line I need but that seems very inefficient, especially since I'm working with ~58,000 lines. Is there a way in the Java API to go directly to a set line?
EDIT: For now I've just read all values into an ArrayList and then pulled values from there but if anyone has a better solution then feel free to post it.Last edited by TheNadz; 06-26-2011 at 07:12 AM.
- 06-26-2011, 07:12 AM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
- 06-26-2011, 09:26 AM #3
Unless the lines are all the same length, there's no way to know the offset of any particular line without reading all the lines before it.
If the file doesn't change much, you could read it once and create an index file that stores the offsets of the beginnings of each line. Then you could go directly to any line using the class that sunde linked.Get in the habit of using standard Java naming conventions!
- 06-26-2011, 11:00 AM #4
Similar Threads
-
Reading a specific line from a file
By efebatistaarda in forum New To JavaReplies: 6Last Post: 02-22-2011, 02:57 PM -
How to read file line by line with fixed number of characters
By trkece in forum New To JavaReplies: 1Last Post: 02-13-2011, 03:09 PM -
Write to a specific line in a file
By phantom06 in forum New To JavaReplies: 1Last Post: 02-05-2011, 06:32 PM -
read a specific line in an input file
By sara12345 in forum Advanced JavaReplies: 7Last Post: 01-03-2010, 10:40 PM -
Need to read an .ini and .abook file line by line (both files contain texts)
By ollyworks in forum Java AppletsReplies: 4Last Post: 09-10-2009, 10:18 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks