dcsimg
reading and updating from a text file
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Monday, July 29, 2002 12:49 AM

I am trying to read data from .txt file using java. The data format contain in this file are like below: data type 10 varchar data type 10 number data type 30 varchar eg: USERID  &nbsp POINT &nbsp USERNAME 0272055259  &nbsp Tan Yoke Yew 0272120212  &nbsp Patrick John 4505207572  &nbsp Saiful 7512642510  &nbsp Sara Gopal First, I will extract the first userid from the text file and then compare with the userid in my oracle database. In this case, I will use the sql statement like this: select * from customer where userid = '0272055259' If there is a user i   More>>

I am trying to read data from .txt file using java. The data format contain
in this file are like below:



data type 10 varchar data type 10 number data
type 30 varchar

eg:


USERID  &nbsp POINT &nbsp USERNAME

0272055259  &nbsp Tan Yoke Yew

0272120212  &nbsp Patrick John

4505207572  &nbsp Saiful

7512642510  &nbsp Sara Gopal



First, I will extract the first userid from the text file and then compare
with the userid in my oracle database. In this case, I will use the sql
statement like this: select * from customer where userid = '0272055259'



If there is a user in the customer table, then i will be able retrieve the
field call POINT inside the oracle database. After that i have to insert the
point inside the text file (as you can see there is a space in between
USERID and USERNAME). This process will loop until end of the text file.



May I know how to implement this? Thanks for help!

   <<Less

Re: reading and updating from a text file

Posted By:   Alex_Kobyakov  
Posted On:   Tuesday, July 30, 2002 12:39 AM

You can use MessageFormat to store format for your file.
E.g., MessageFormat mf = new MessageFormat({0}, {1}, {2});

After reading point from database and userid, username from file, populate message format with data and write it to output file.

String result = mf.format(userid, point, username);
output.write(result);

Should be no problem writing this without MessageFormat, but you may also use it's .parse function for reading data out of file, but probably it will require modifications in your file structure.
About | Sitemap | Contact