Difference between revisions of "IO"

From Suhrid.net Wiki
Jump to navigationJump to search
Line 5: Line 5:
 
* FileReader - read character levels - variety of read() methods. Usually wrapped in a BufferedReader.
 
* FileReader - read character levels - variety of read() methods. Usually wrapped in a BufferedReader.
 
* BufferedReader - Reads large chunks of files and keeps it in the buffer. Subsequent requests are got from the buffer thus minimizing the number of times time intensive file IO is performed.
 
* BufferedReader - Reads large chunks of files and keeps it in the buffer. Subsequent requests are got from the buffer thus minimizing the number of times time intensive file IO is performed.
* Similarly:
+
Similarly:
 
* FileWriter - write to character files.
 
* FileWriter - write to character files.
 
* BufferedWriter - Keeps data in buffer and writes large chunks of buffer to file at once, minimizing file IO.
 
* BufferedWriter - Keeps data in buffer and writes large chunks of buffer to file at once, minimizing file IO.
 
* PrintWriter - Has a lot of convenience methods and constructors (takes a File or String etc). Methods like format(), printf() and append() make PrintWriters powerful.
 
* PrintWriter - Has a lot of convenience methods and constructors (takes a File or String etc). Methods like format(), printf() and append() make PrintWriters powerful.
  
* Remember:
+
Remember:
 
* '''For Characters''' - Reader and Writer classes are used.
 
* '''For Characters''' - Reader and Writer classes are used.
 
* '''For Bytes''' - Stream classes are used.
 
* '''For Bytes''' - Stream classes are used.
  
 
[[Category:OCPJP]]
 
[[Category:OCPJP]]

Revision as of 22:29, 17 August 2011

Basic Classes

  • The File class is an abstract representation of files and directory pathnames. It works at a higher level, cant be used to read/write data.
  • FileReader - read character levels - variety of read() methods. Usually wrapped in a BufferedReader.
  • BufferedReader - Reads large chunks of files and keeps it in the buffer. Subsequent requests are got from the buffer thus minimizing the number of times time intensive file IO is performed.

Similarly:

  • FileWriter - write to character files.
  • BufferedWriter - Keeps data in buffer and writes large chunks of buffer to file at once, minimizing file IO.
  • PrintWriter - Has a lot of convenience methods and constructors (takes a File or String etc). Methods like format(), printf() and append() make PrintWriters powerful.

Remember:

  • For Characters - Reader and Writer classes are used.
  • For Bytes - Stream classes are used.