Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 249
  • Last Modified:

File processing using Java

Hi,

How can I read a pipe delimited multi-record file using Java, make some data conversions/modifications to the elements of the file and write the updated input file elements to a pipe delimited output file?

For example, if the input file is as follows:

XYZ|4939.55|555|Java|XML
ABC|566.44|383|Visual Basic|ASP

Convert 4th field ("Java" to "Programming" and "Visual Basic" to "Windows") and divide the 3rd field by 100.

My output file should be like this:

XYZ|4939.55|5.55|Programming|XML
ABC|566.44|3.83|Windows|ASP


Thanks for your help.

0
sri_bali
Asked:
sri_bali
  • 2
1 Solution
 
Mayank SAssociate Director - Product EngineeringCommented:
1. Read the file line-by-line using BufferedReader and readLine ().

2. Use a StringTokenizer to de-limit the string at pipes ( | ) and copy the four substrings into an array of Strings.

3. Perform what-ever operations/ modifications you have to perform, converting the String to integer-type using Integer.parseInt () wherever required.

4. Write the output in the same fashion into another file, converting integers to Strings using Integer.toString (), delimiting the strings by pipes ( | ).

Mayank.
0
 
CleanupPingCommented:
sri_bali:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Recommendation: Accept mayankeagle's comment as answer.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now