wood burning stoves 2.0*
The moose likes I/O and Streams and the fly likes Searching a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Searching a file" Watch "Searching a file" New topic
Author

Searching a file

Chris Fetterley
Ranch Hand

Joined: May 13, 2003
Posts: 51
I am trying to create a program that will bring in a file, search for a variable entered into a text field and and return the value after it in another text field. I'm assuming that I want to use randomAccessFile to do this? but I keep running into errors with String variables. is there an easy way to do this?
Leslie Chaim
Ranch Hand

Joined: May 22, 2002
Posts: 336
Does your file have fixed-length records? If not then randomAccessFile is only going to cause you headaches
What kind of file is it; I am not sure what you mean by variable.
Is this some little GUI that you are writing?


Normal is in the eye of the beholder
Chris Fetterley
Ranch Hand

Joined: May 13, 2003
Posts: 51
yes it is a GUI. I'm trying to use one textfield to have the user enter the data and then have that data searched through the file followed by outputting the next five letters in the next field. So should I use a dataInputStream then?
Leslie Chaim
Ranch Hand

Joined: May 22, 2002
Posts: 336
So should I use a dataInputStream then?
It all depends on the structure of your file. I will make an assumption based on:

then have that data searched through the file followed by outputting the next five letters in the next field.

That you file is a text file with the following format:

If indeed this is the format, I'd use a some LineReader (BufferedReader or whatever) then use regular expression as follows:

Does this help?
[ June 20, 2003: Message edited by: Leslie Chaim ]
Chris Fetterley
Ranch Hand

Joined: May 13, 2003
Posts: 51
for the "......." do I want to convert the information entered in my textfield to a string and have it checked that way?

Thanks for the help!!
Leslie Chaim
Ranch Hand

Joined: May 22, 2002
Posts: 336
do I want to convert the information entered in my textfield to a string and have it checked that way?
Not sure I understand your question. Please elaborate and give some examples.
Thanks for the help!!
So, are you a happy camper or not
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Searching a file
 
Similar Threads
Disabling html:text in Struts dynamically
adding text to a database
changing font type and size
readOnly disable style
I have a doubt