Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
Java Programming Language (3) - Input/Output Stream – Company Logo @ Dong In Shin DCS lab Seoul National University Stream Stream? Why JAVA uses Stream? Input source 또는 output destination을 갖는 순서화된 일련의 자료(sequence of bytes)를 나타내는 abstract input/output model I/O device에 독립적인 입출력 방식을 제공 대부분의 method는 throws IOException java.io package내의 모든 exception class는 IOException의 직간접적인 하위 클래스이다. [email protected] Input/Output Stream Data Program Input Stream Data [email protected] Output Stream Stream Input/Output class의 종류 입출력 자료 종류 Byte stream : InputStream , OutputStream Character stream : Reader , Writer Binary data 또는 byte 단위의 문자 자료의 입출력 방법 제공 Unicode(2 byte) 문자 자료의 입출력 방법 제공 입출력 장치 종류 입출력 장치 종류(file, network, …)에 따라 다른 stream class 들에 의해 지원 [email protected] Stream Input/Output class의 종류 입출력 기능(filtering) 기존의 stream에 부가적인 입출력 기능을 추가하여 제공하 는 stream 문자 세트 변환 자료값을 string 표현으로 출력 PrintWriter, PrintStream 버퍼링(buffering)… 자료의 내부 표현 값을 그대로 입출력 InputStreamReader, OutputStreamWriter DataInputStream, DataOutputStream 객체 입출력 ObjectInputStream, ObjectOutputStream [email protected] Byte Stream Classes [email protected] Character Stream Classes [email protected] Data Sink Stream Classes String, file, pipe와 같이 특정한 data를 읽거나 쓸 때 사용한 다 Sink type Character stream Byte stream Memory CharArrayReader CharArrayWriter ByteArrayInputStream ByteArrayOutputStream StringReader, StringWriter StringBufferedInputStream (Deprecated.) Pipe PipedReader PipedWriter PipedInputStream PipedOutputStream File FileReader FileWriter FileInputStream FileOutputStream [email protected] InputStream / OutputStream Abstract byte input/output stream class int read( ) int read(byte cbuf[ ]) int read(byte cbuf[], int offset, int length) int write( ) int write(byte cbuf[ ]) int write(byte cbuf[], int offset, int length) void flush() void close() : stream을 닫을 때 사용하는 method [email protected] FileInputStream / FileOutputStream Input source 와 Output destination이 file인 byte stream class FileInputStream class construct new FileInputStream(String name)throws FileNotFoundException new FileInputStream(File file)throws FileNotFoundException FileOutputStream class New FileOutputStream(String name, boolean append =false) throws FileNotFoundException New FileOutputStream(File file) throws FileNotFoundException [email protected] FileInputStream/ FileOutputStream [email protected] FileInputStream/ FileOutputStream [email protected] Standard I/O 운영체제가 제공하는 기능에 의해 프로그램의 수정없이 다양한 입출력 장치(keyboard, monitor ,file)로 입출력 제공 표준 입출력 객체 InputStream System.in OutputStream System.out Standard input stream (default 로 keyboard) Standard output stream (default로 monitor ) PrintStream System.err Standard error stream (default로 monitor) [email protected] Standard I/O result [email protected] Reader/Writer Input source로 부터 Unicode 문자 자료(char, char[], string)을 읽어들이고 제어할 수 있는 method를 제공하는 abstract character input/output stream class int read( ) int read(char cbuf[ ]) int read(char cbuf[], int offset, int length) int write( ) int write(char cbuf[ ]) int write(char cbuf[], int offset, int length) FileReader/FileWriter : FileInputStream , FileOutputStream과 기능이 거의 동일 [email protected] InputStreamReader/OutputStreamWriter Byte stream 을 Character stream과 연결시켜 Unicode 문자를 입 출력 할 수 있다. Byte stream의 문자 인코딩을 지정. [email protected] InputStreamReader/OutputStreamWriter [email protected] Memory Stream [email protected] Memory Stream [email protected] I/O 관련 기본 exception class java.io 및 java.net package의 모든 exception class는 java.io.IOException의 extended class 따라서 IOException handling 만으로 모두 처리가능 [email protected] Next 입출력 기능에 따른 stream class(filtering) Buffering, string presentation… Object stream 객체 직렬화( Serializable interface ) [email protected]