text file : Java Glossary

*0-9ABCDEFGHIJKLMNOPQRSTUVWXYZ (all)

text file
A text file is simple string of printable characters (plus space, tab, Cr and Nl) all in the same encoding stored in a file. Any formatting structure is handled by printable characters, the way XML (extensible Markup Language) or HTML (Hypertext Markup Language) do. In contrast, Microsoft Word uses an inscrutable binary format for storing text and formatting. OpenOffice stores its word processing documents in compressed text files. You can’t explore them without decompressing them first.

Text files may contain 8-bit chars, 16-bit chars or even 32-bit chars encoded as 8-bit surrogates.

Lines are terminated by the misnamed line.separator string which you can discover with

There should be a terminator on the last line, even though system property name line.separator suggests there should not. Putting the terminator there will not be treated as a final empty line. Programs will usually still work if the final terminator is missing, but in earlier versions of Java readLine would not read the last line without it.

There is no mechanism to keep track of which encodingwas used to write a text file. You just have to know. The Encoding Recogniserwill help you guess. Originally this caused no problem because people rarely exchanged files except with coworkers. Everyone’s files were encoded in the same local national encoding. Today people share files all over the globe. It is best to use ASCII (American Standard Code for Information Interchange) for 7-bit chars, ISO-8859-1 for 8-bit and UTF-8 for 16-bit.

The classes to write text files include File, FileOutputStream, OutputStreamWriter and BufferedWriter. The classes to read text files include File, FileInputStream, InputStreamReader and BufferedReader. The File I/O Amanuensis will generate Java code for you to read and write text files (as well as other types).

Other ways of storing text include:


This page is posted
on the web at:

http://mindprod.com/jgloss/textfile.html

Optional Replicator mirror
of mindprod.com
on local hard disk J:

J:\mindprod\jgloss\textfile.html
Canadian Mind Products
Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

IP:[65.110.21.43]
Your face IP:[3.143.0.157]
You are visitor number