<<< I/O class hierarchy | Index | Formatted output: PrintWriter class >>> |
Class java.io.BufferedWriter extends the java.io.Writer class.
BufferedWriter implements buffered output of character streams
java.io.PrintWriter adds character formatting for primitive types and Strings
FileWriter implements low-level writing of character files
import java.io.*; import java.nio.file.*; public class TextOutputDemo { public static void main(String[] args) { // Get a Path object for the file Path booksPath = Paths.get( "C:/myfiles/dummy.txt" ); File booksFile = booksPath.toFile(); //Write data to the file try { PrintWriter outp = new PrintWriter( // output formatting functionality new BufferedWriter( // implements stream buffer for character output new FileWriter(booksFile))); // basic writing of character files // character output: outp.println("book\tBeginning Java Programming\t49.50"); outp.close(); } catch (IOException e) { System.out.println(e); } } }//class TextOutputDemo
Note that File objects are not files! The File class keeps metadata describing either file or directory, useful when working with files and directories of the file system.
<<< I/O class hierarchy | Index | Formatted output: PrintWriter class >>> |