• Post Reply Bookmark Topic Watch Topic
  • New Topic

Read specific String value from File....Help..

 
sam patel
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
THis is what i want to do.
I have
===============================================
1. Provider Name: Abrar, Naim, MD
Specialty(ies): Internal Medicine
Address: 1149 Old Country Road, Bldg C Suite 1, Riverhead, NY 11901
Phone Number(s): (631) 369-3333
� Provider Detail
� Enrollment IDs
Map

2. Provider Name: Alter, Seymour, MD
Specialty(ies): Internal Medicine
Address: 222 East Main Street, Smithtown, NY 11787
Phone Number(s): (631) 265-1177
� Provider Detail
� Enrollment IDs
Map

3. Group Name: AMB Medical Services, PC
Address: 1 Kings Hwy., Hauppauge, NY 11788
Phone Number(s): (631) 348-4900
Providers:
Liang, Weining, MD
Specialty(ies): Internal Medicine
� Provider Detail
� Enrollment IDs
Map
==================================
about 200 names information in my file and i want to read each line and write only Group Name, Address, Phone Number in another file.
Can someone please show me how this can be done...
Any help will be greatly apprecited..
Thanks.
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would use a BufferedReader (instantiated with a FileReader), and use the readLine() method in a loop to pull out each line of the file into a String. Use that String to determine if it contains "Group Name:". If so, you know you are in a grouping of data that you need to pull out the "Address" and "Phone Number". So you're going to have an inner loop that gets those lines out, and breaks when you've gotten that data (which will cause the outer loop to continue to the next instance of a group).
Create some data object that holds the group name, phone number and address, and stick each object into a collection once the data is populated in the object. After you are finished with the file, pass that collection on to whatever class(es) is writing the new file. Use a PrintWriter and it's corresponding println( String ) method to write out the data for each group as you iterate over the collection.
If you have some code that you have written, post it and we can help you refine it. Otherwise, use these suggestions to help develop something and we can go from there.
Check out the Java I/O API if you haven't, and the I/O Tutorialif you are not completely comfortable with Java I/O.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!