|
Subject:
|
data parse from text file
|
|
Posted By:
|
mameworld
|
Post Date:
|
1/9/2006 11:27:50 AM
|
Hello, my name is Jay. I have taken a course in Java, and written several simple programs. I am a little bit rusty on the parse function, what I am wanting to do is take data in text file format, parse the data, and output it in the following format
title firstName middleInitial lastName streetAddress city, state zip
I want to export it into a new text file like that. All other data can be disregaurded at this point. I know how to do all of the file I/O stuff, but as I said, I am not really sure how to parse the data and put it in that format. any help would be very much appreciated. This is my first on the job assignment as a programmer, so I want to make sure I can get it working.
here is the EXACT format of the original text file:
"fullName", "title", "firstName", "lastName", "middleInitial", "streetAddress", "city", "state", "zip", "phoneNumber", "Age", "income" "fullName", "title", "firstName", "lastName", "middleInitial", "streetAddress", "city", "state", "zip", "phoneNumber", "Age", "income" "fullName", "title", "firstName", "lastName", "middleInitial", "streetAddress", "city", "state", "zip", "phoneNumber", "Age", "income" "fullName", "title", "firstName", "lastName", "middleInitial", "streetAddress", "city", "state", "zip", "phoneNumber", "Age", "income" "fullName", "title", "firstName", "lastName", "middleInitial", "streetAddress", "city", "state", "zip", "phoneNumber", "Age", "income" Thanks again.
-jay
|
|
Reply By:
|
adarsh83
|
Reply Date:
|
1/14/2006 5:30:31 AM
|
It is a CSV (comma separated values) file. First get the reader ready by using a BufferedReader. Then, as you scan line by line, using readLine() method, do this:
System.out.println("Full Name\t Title\t First Name\t Last Name\t Middle Initial\t Street Address\t City\t State\t Zip\t Phone Number\t Age\t Income");
String line = null;
while( (line = br.readLine()) != null) { String [] data = line.split(","); for(int i = 0; i < data.length i++) { System.out.print(data[i]); } System.out.println(); }
________ Adarsh
________ Adarsh
|
|