* Chapter 18 I/O (Input/Output) * Introduction to I/O Creating a good input/output (I/O) system is one of the more difficult tasks for a language designer. This is evidenced by the number of different approaches. The challenge of I/O: Different sources Different sinks Files, the console, network connections Sequential, random-access, buffered, binary, character, by lines, by words * Introduction to I/O Class File I/O Stream Input Streams/ Output Streams Node Streams/ Processing Streams File Streams/ Buffer Streams Print Streams Data Streams /Object Streams RandomAccessFile Compression XML * Introduction to I/O Sally Black Tom Blue Judy Green Iris Orange Randy Red Judy Green J u d y String 01001010 Byte 1 Bit line File 0 1 2 3 4 …… n-1 n A file containing n Bytes * Introduction to I/O Stream in Java I/O In Java, the input and output of data are operated by “Stream”. There are a lot of “Stream” in Java for different data types. * Class File Introduction
represent either the name of a particular file or the names of a set of files in a directory. Constructor summary of Class File public File (String pathname) Creates a new File instance by converting the given pathname string into an abstract pathname. public File(String parent, String child) Creates a new File instance from a parent pathname string and a child pathname string. * Class File Methods summary of class File public boolean canRead() public boolean canWrite() public boolean exists() public boolean isDirectory() public boolean isFile() public boolean isHidden() public long lastModified() public long length() public String getName() public String getPath() * Class File Methods summary of class File public boolean createNewFile() throws IOException Atomically creates a new, empty file named by this abstract pathname if and only if a file with this name doe