Results 1 to 5 of 5
Thread: searching a string in a file
- 03-26-2012, 09:38 AM #1
Member
- Join Date
- Mar 2012
- Posts
- 12
- Rep Power
- 0
- 03-26-2012, 02:02 PM #2
Re: searching a string in a file
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")If you don't understand my response, don't ignore it, ask a question.
- 03-27-2012, 02:25 AM #3
Re: searching a string in a file
Haven't-a-clue questions don't belong in Advanced Java. Moving to New to Java.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 03-27-2012, 12:56 PM #4
Member
- Join Date
- Mar 2012
- Posts
- 12
- Rep Power
- 0
Re: searching a string in a file
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?
- 03-27-2012, 01:12 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: searching a string in a file
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.Please do not ask for code as refusal often offends.
Similar Threads
-
Searching for tags in a string
By Warcrea in forum New To JavaReplies: 1Last Post: 02-15-2012, 11:44 PM -
Searching for a string in different log files
By nitin kishore in forum Advanced JavaReplies: 6Last Post: 09-14-2011, 09:32 PM -
searching for a word in a string
By Brian-82 in forum New To JavaReplies: 1Last Post: 05-11-2011, 07:19 PM -
Searching a string from a text file using Swing Buttons
By pradeep1_mca@yahoo.com in forum AWT / SwingReplies: 2Last Post: 09-15-2008, 09:50 AM -
Searching a String from Text file using Swings .
By pradeep1_mca@yahoo.com in forum AWT / SwingReplies: 4Last Post: 09-09-2008, 05:29 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks