Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 9th, 2006, 12:27 PM
Registered User
 
Join Date: Jan 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default data parse from text file

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
 
Old January 14th, 2006, 06:30 AM
Authorized User
 
Join Date: Dec 2005
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to Parse Query Text neha2007 BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 June 13th, 2007 07:21 AM
How to Parse - Parsing Flat File Data - Asp darinsee Classic ASP Databases 5 May 24th, 2004 04:11 PM
Parse - Parsing Flat File Data - Asp darinsee Classic ASP Basics 1 May 22nd, 2004 08:39 AM
Parse - Parsing Flat File Data - Asp darinsee Classic ASP Components 1 May 22nd, 2004 08:19 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.