text file : Java Glossary

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).


CMP homejump to top You can get the freshest copy of this page from: or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror)
http://mindprod.com/jgloss/textfile.html J:\mindprod\jgloss\textfile.html
logo
Please email your , letters to the editor, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email. If you want your message, your name or email kept confidential, not considered for public posting, please explicitly specify that. Unless you state otherwise, I will treat your message as a letter to the editor that I may or may not publish in the feedback section. After that, it will be too late to retract it. If you disagree with something I said, please quote it and cite the web page where you found it, tell me why you think it is wrong, and, if possible, provide some supporting evidence. Threatening to kill me or spouting obscenities has yet to persuade me to change my mind.
mindprod.com IP:[65.110.21.43]
view BlogYour face IP:[38.107.179.213]
You are visitor number 11.