Read and write to an ASCII Text file

Reply

Join Date: Mar 2004
Posts: 1
Reputation: Ron is an unknown quantity at this point 
Solved Threads: 0
Ron Ron is offline Offline
Newbie Poster

Read and write to an ASCII Text file

 
0
  #1
Mar 1st, 2004
I am very new to Java and I'm trying to write a Java program to read a ASCII text file, modify a field and save it. I'm not sure how to create the file definition so I can break out the individual fields. The records and fields are all fixed length.

If anyone can assist, it would be greatly appreciated.

Thanks.

Ron
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 10
Reputation: Meldroz is an unknown quantity at this point 
Solved Threads: 0
Meldroz Meldroz is offline Offline
Newbie Poster

Re: Java Help

 
0
  #2
Mar 15th, 2004
Hey,

yeah java IO is not exactly the easiest thing to learn, but you do need to know a few of the basic classes to use. The easiest way to read in an ASCII text file is to use this:

ps: make sure you catch the exceptions or else your days will be numbered believe me

InputStream ist = new FileInputStream(textfile);
BufferedReader istream = new BufferedReader(new InputStreamReader(ist));
String text = istream.readLine(); //just read the first line in the text file

and to break the records well i guess you have to use the StringTokenizer class,
i assume you know what that is if you don't i suggest you pay a little vivist to Java's API web page.
here's a quick look at what it would look like form here on:
StringTokenizer st;
while ( text != null )// while more line in text
{
st = new StringTokenizer(text) // break each words or whatever in to single //tokens
while ( st.hasMoreToken() ) // not sure about the spelling here
{
process each token here
}

read the next line
} // end of while ( text != null )

hope that help you get started.
take care,
Mel
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC