| | |
Read and write to an ASCII Text file
![]() |
•
•
Join Date: Mar 2004
Posts: 1
Reputation:
Solved Threads: 0
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
If anyone can assist, it would be greatly appreciated.
Thanks.
Ron
•
•
Join Date: Mar 2004
Posts: 10
Reputation:
Solved Threads: 0
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
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
![]() |
Similar Threads
- Using a static method to read data from text file (Java)
- Read text file word by word (Pascal and Delphi)
- How read and write int values from/to a file? (C++)
- How to write enter in text file (C)
- Manipulate text file using Visual Studio .NET 2003 (VB.NET)
- read-delete lines from a text file (PHP)
- Read a specific line from a text file - how to ? (Java)
- Trying to write information in a text file -> Array (Java)
- read from database and writing the contents into a text file (C)
Other Threads in the Java Forum
- Previous Thread: Need help with looping some sounds
- Next Thread: java interfaces
| Thread Tools | Search this Thread |
3d 6 @param actuate affinetransform android api applet application arc array arrays automation balls binary bluetooth bold business c++ class client code codesnippet collections compare component coordinates database defaultmethod detection doctype dragging ebook eclipse educational error file fractal froglogic game givemetehcodez graphics gui guitesting helpwithhomework hql html ide ideas image ingres input integer intersect invokingapacheantprogrammatically j2me java java.xls javaexcel javaprojects jni jpanel jtextarea julia keytool linux list map method methods mobile mysql netbeans nextline parameter php pong problem program project recursion recursive rim scanner sell server set sms sort sql string sun swing swt terminal threads tree web websites windows





