• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Searching a file

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Chris Fetterley
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic