473,406 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Java HELP: How do you read in a Text File (Fixed Length)

I am very new to Java. How would you go about making Java program that
reads in a fixed length text file (myfile.txt) and pass the data into
a table in an sql table?

The text file data looks something like this:

123456John Smith Acme Boxes Inc 100 Someplace Drive
222222Sarah E. ConnorCyberdyne Systems Corp 1 Connorsbane Plaza
333333Martin Fry Care Of: Joseph P Helstrom200 Hive Avenue

Any help would be very appreciated.

Harvey
Jul 17 '05 #1
5 5184
1.if all rows and all data (IDno, Name, Company, Adress) are equal length
then you can do it easily if you make a loop for1 to last IDno and substring
data.

or

2. put some delimiter beetween data (i.e. |) then you have

123456|John Smith |Acme Boxes Inc |100 Someplace Drive|
222222|Sarah E. Connor|Cyberdyne Systems Corp |1 Connorsbane Plaza|
333333|Martin Fry |Care Of: Joseph P Helstrom|200 Hive Avenue|

now with stringtokenizer go thru your file.

or

3. use XML :)

Hrvoje J. Somun

"H Brown New To It" <br*****@dhhs.state.sc.us> wrote in message
news:5b**************************@posting.google.c om...
I am very new to Java. How would you go about making Java program that
reads in a fixed length text file (myfile.txt) and pass the data into
a table in an sql table?

The text file data looks something like this:

123456John Smith Acme Boxes Inc 100 Someplace Drive
222222Sarah E. ConnorCyberdyne Systems Corp 1 Connorsbane Plaza
333333Martin Fry Care Of: Joseph P Helstrom200 Hive Avenue

Any help would be very appreciated.

Harvey

Jul 17 '05 #2
"Hrvoje Somun" <hr****************@zg.tel.hr> wrote in message news:<bo**********@sunce.iskon.hr>...
1.if all rows and all data (IDno, Name, Company, Adress) are equal length
then you can do it easily if you make a loop for1 to last IDno and substring
data.

or

2. put some delimiter beetween data (i.e. |) then you have

123456|John Smith |Acme Boxes Inc |100 Someplace Drive|
222222|Sarah E. Connor|Cyberdyne Systems Corp |1 Connorsbane Plaza|
333333|Martin Fry |Care Of: Joseph P Helstrom|200 Hive Avenue|

now with stringtokenizer go thru your file.

I agree with the first method even though you didn't tell him any file
stuff ie. how to open the file how to read through it etc.

but ...
i'm intrigued
you propose
or

3. use XML :)


as a solution
please tell .... how would you use xml to do something like this and
integrate it into java?

please tell me
Jul 17 '05 #3

"delusion" <my*******************@yahoo.co.uk> wrote in message
news:e2**************************@posting.google.c om...
"Hrvoje Somun" <hr****************@zg.tel.hr> wrote in message news:<bo**********@sunce.iskon.hr>...
1.if all rows and all data (IDno, Name, Company, Adress) are equal length then you can do it easily if you make a loop for1 to last IDno and substring data.

<snip>
I agree with the first method even though you didn't tell him any file
stuff ie. how to open the file how to read through it etc.
yes, but that part is in any java tutorial

but ...
i'm intrigued
you propose
or

3. use XML :)


as a solution
please tell .... how would you use xml to do something like this and
integrate it into java?

please tell me

if he wants to insert data from *.txt to rational database and use java as a
tool to do it he can use xml file instead of txt file, he sould transform
his txt file into smoething like;
<customer ID="123456">
<name>John Smith</name>
<company>Acme Boxes Inc</comapny>
<adress>100 Someplace Drive</adress>
</customer>

use some parser (if all his data about customers is in a single file then
SAX), and insert data into database.
?
i did it few times.
yes, if he cant change txt file then this way is not good, but if he is just
starting to build hiss application he should use this metod(XML has many
other advantages.....)
Hrvoje J. Somun
Jul 17 '05 #4
sorry for fast typing and mistakes
(btw no, i don t have dyslexia) :)
Jul 17 '05 #5
On Thu, 6 Nov 2003 16:19:29 +0100, "Hrvoje Somun"
<hr****************@zg.tel.hr> wrote or quoted :
sorry for fast typing and mistakes
(btw no, i don t have dyslexia) :)


see http://mindprod.com/jgloss/newsreader.html

Agent has a spell checker.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

114
by: Maurice LING | last post by:
This may be a dumb thing to ask, but besides the penalty for dynamic typing, is there any other real reasons that Python is slower than Java? maurice
20
by: titi | last post by:
Question The road and traffic authority for a small country currently uses a system to store information about all 'currently' licensed drivers. A licensed driver has the following info stored...
10
by: Alex Gerdemann | last post by:
Hello, I have spent a bunch of time converting a Java program I wrote to C++ in order to improve performance, and have found that it is not necessarily faster. Specifically, I'm writing a...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
7
by: Hallvard B Furuseth | last post by:
I'm trying to clean up a program which does arithmetic on text file positions, and also reads text files in binary mode. I can't easily get rid of it all, so I'm wondering which of the following...
0
by: VeeraLakshmi | last post by:
I am doing a project for internet control using Java,PHP and MySql.All sites should go through the proxy server only.We are giving access rights as allow or deny to the sites.If we type the...
2
by: lilyumestar | last post by:
This project is due by Tuesday and I haven't even gotten half of it done. Can anyone please help me with this Exception error? I've been trying to figure it out for several hours Error Message ...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.