?
Solved

File processing using Java

Posted on 2003-03-25
4
Medium Priority
?
240 Views
Last Modified: 2010-04-17
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
Comment
Question by:sri_bali
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 30

Accepted Solution

by:
Mayank S earned 300 total points
ID: 8208043
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
 

Expert Comment

by:CleanupPing
ID: 9446805
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
 
LVL 30

Expert Comment

by:Mayank S
ID: 9451892
Recommendation: Accept mayankeagle's comment as answer.
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this post we will learn different types of Android Layout and some basics of an Android App.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Simple Linear Regression

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question