943,866 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 45677
  • Java RSS
Mar 1st, 2004
0

Read and write to an ASCII Text file

Expand Post »
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
Similar Threads
Ron
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Ron is offline Offline
1 posts
since Mar 2004
Mar 15th, 2004
0

Re: Java Help

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Meldroz is offline Offline
11 posts
since Mar 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Need help with looping some sounds
Next Thread in Java Forum Timeline: java interfaces





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC