A basic topic in programming is the processing of files. If information is to be stored until the next program start, this data is written to the hard disk in files. Thus the information remains also after the termination of the program.
After opening a file, it remains locked for further accesses from outside. At this moment, a file can only be processed by the program that opened the file. If you forget to close a file, it remains locked at least until the end of the program. With some operating systems also up to the reboot of the system.
File accesses take place in Java via data streams with readers and writers. Buffering via BufferedWriter
optimizes the procedure of a FileWriter
. With the BufferedWriter
the write performance is increased, since each byte is not written individually and thus the number of write accesses is reduced.
Equivalent to the FileWriter
there is the FileReader
or the optimized version of the BufferedReader
, for reading from files.
As of Java version 7, the utility class java.nio.file.Files
was added. This contains methods with which a byte array, a string or a list of strings can be written to or loaded from a file with a single command.