hello guys
i have a text file of size 10mb. i need to search for a string and get its position in the file.
also is it possible to search a file from a given position to end-of-file?
please help me out.........
Printable View
hello guys
i have a text file of size 10mb. i need to search for a string and get its position in the file.
also is it possible to search a file from a given position to end-of-file?
please help me out.........
What have you tried so far?
Read the file line by line
Search each line as it is read.
The RandomAccessFile class will allow you to read at any byte location in the file. If the file has lines there is no way to know where lines begin unless the size of all the lines is known.
A line is a String that ends with a lineend character. ("\n")
Haven't-a-clue questions don't belong in Advanced Java. Moving to New to Java.
db
norm:
the file under consideration is a csv file. there are 12 fields seperated by comma in each line.
consider this situation:
An outside application keeps on appending "set of records" for every 5 sec in the csv file.
I need to insert these newly appended records in my database
these are the constraints:
1) there is no primary key i.e no record has a unique field/collection of fields
2) the no of records inserted in the csv file per 5 sec may vary
so how do i approach this situation? what is the best way to keep track of last record inserted in the database from the text file?or how do i know from which record i need to insert into the database after 5 sec?
That sounds a rather fragile thing.
I hope this is simply papering over an already existing old system...:)
Anyway, you'll need to maintain a line number somewhere so you know which ones have already been inserted, then simply read through the file until you hit that line number (there's a LineNumberReader class, or something like that).
This will, presumably, need to be persisted, so it will have to be in the db for safe keeping.