Welcome to Dream.In.Code
Become a Java Expert!

Join 149,477 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,741 people online right now. Registration is fast and FREE... Join Now!




Using Java to parse data

 
Reply to this topicStart new topic

Using Java to parse data, Examples

princejlynn
15 May, 2007 - 08:01 AM
Post #1

D.I.C Head
**

Joined: 15 Jan, 2007
Posts: 77


My Contributions
Does anyone know of a site that provides examples of code for parsing data from text documents or excel documents? I would like to learn how to do this.
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Using Java To Parse Data
15 May, 2007 - 08:51 AM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,348



Thanked: 51 times
Dream Kudos: 25
My Contributions
Do you have a specific example? Data parsing is pretty easy in java - parsing is mostly driven by the logic behind the application. You can use java functions and classes to read a text file into a string, or strings, or any data type applicable, then use the string functions to further separate.

Do you need to parse at a line by line level? word by word? character by character?
User is online!Profile CardPM
+Quote Post

princejlynn
RE: Using Java To Parse Data
15 May, 2007 - 09:06 AM
Post #3

D.I.C Head
**

Joined: 15 Jan, 2007
Posts: 77


My Contributions
QUOTE(princejlynn @ 15 May, 2007 - 09:01 AM) *

Does anyone know of a site that provides examples of code for parsing data from text documents or excel documents? I would like to learn how to do this.

For example, if I wanted to parse a spreadsheet or a document that contained names, phone numbers, addresses, etc. and put them into this format:

#BeginRecord
(Data Goes Here)
#Name
(Data Goes Here)
#PhoneNumber
(Data Goes Here)
#Address
(Data Goes Here)
#EndRecord

What would be the best way to do this? I am just learning Java, but would like to continue using it in my work environment, and this is what I need to use it for.

Thanks.....[quote]
User is offlineProfile CardPM
+Quote Post

princejlynn
RE: Using Java To Parse Data
16 May, 2007 - 02:55 AM
Post #4

D.I.C Head
**

Joined: 15 Jan, 2007
Posts: 77


My Contributions
[quote name='princejlynn' date='15 May, 2007 - 10:06 AM' post='225484']
[quote name='princejlynn' post='225469' date='15 May, 2007 - 09:01 AM']
Does anyone know of a site that provides examples of code for parsing data from text documents or excel documents? I would like to learn how to do this.
[/quote]
For example, if I wanted to parse a spreadsheet or a document that contained names, phone numbers, addresses, etc. and put them into this format:

#BeginRecord
(Data Goes Here)
#Name
(Data Goes Here)
#PhoneNumber
(Data Goes Here)
#Address
(Data Goes Here)
#EndRecord

What would be the best way to do this? I am just learning Java, but would like to continue using it in my work environment, and this is what I need to use it for.

Thanks.....[quote]
[/quote]
Any suggestions??[quote]
User is offlineProfile CardPM
+Quote Post

Programmist
RE: Using Java To Parse Data
17 May, 2007 - 02:31 AM
Post #5

Four-letter word
Group Icon

Joined: 2 Jan, 2006
Posts: 1,250



Thanked: 11 times
Dream Kudos: 100
Expert In: Java

My Contributions
It depends a lot on the file format. But, generally, you can open a text file in the following manner:


CODE

// all in package java.io I think
BufferedReader input = new
   BufferedReader( new FileReader( new File ("path/to/file/fileName") ) );


Then you can use BufferedReader to access the text data by line or by character.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 03:14PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month