1 / 21

Java Programming Language (3) - Input/Output Stream –

Java Programming Language (3) - Input/Output Stream –. Dong In Shin DCS lab Seoul National University. Stream. Stream? Input source 또는 output destination 을 갖는 순서화된 일련의 자료 (sequence of bytes) 를 나타내는 abstract input/output model Why JAVA uses Stream? I/O device 에 독립적인 입출력 방식을 제공

sereno
Download Presentation

Java Programming Language (3) - Input/Output Stream –

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Java Programming Language (3)- Input/Output Stream – Dong In Shin DCS lab Seoul National University

  2. Stream • Stream? • Input source 또는 output destination을 갖는 순서화된 일련의 자료(sequence of bytes)를 나타내는 abstract input/output model • Why JAVA uses Stream? • I/O device에 독립적인 입출력 방식을 제공 • 대부분의 method는 throws IOException • java.io package내의 모든 exception class는 IOException의 직간접적인 하위 클래스이다. dishin@dcslab.snu.ac.kr

  3. Data Program Input Stream Data Output Stream Input/Output Stream dishin@dcslab.snu.ac.kr

  4. Stream Input/Output class의 종류 • 입출력 자료 종류 • Byte stream : InputStream , OutputStream • Binary data 또는 byte 단위의 문자 자료의 입출력 방법 제공 • Character stream : Reader , Writer • Unicode(2 byte) 문자 자료의 입출력 방법 제공 • 입출력 장치 종류 • 입출력 장치 종류(file, network, …)에 따라 다른 stream class 들에 의해 지원 dishin@dcslab.snu.ac.kr

  5. Stream Input/Output class의 종류 • 입출력 기능(filtering) • 기존의 stream에 부가적인 입출력 기능을 추가하여 제공하는 stream • 문자 세트 변환 • InputStreamReader, OutputStreamWriter • 자료값을 string 표현으로 출력 • PrintWriter, PrintStream • 버퍼링(buffering)… • 자료의 내부 표현 값을 그대로 입출력 • DataInputStream, DataOutputStream • 객체 입출력 • ObjectInputStream, ObjectOutputStream dishin@dcslab.snu.ac.kr

  6. Byte Stream Classes dishin@dcslab.snu.ac.kr

  7. Character Stream Classes dishin@dcslab.snu.ac.kr

  8. Data Sink Stream Classes • String, file, pipe와 같이 특정한 data를 읽거나 쓸 때 사용한다 dishin@dcslab.snu.ac.kr

  9. 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 dishin@dcslab.snu.ac.kr

  10. 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 dishin@dcslab.snu.ac.kr

  11. FileInputStream/ FileOutputStream dishin@dcslab.snu.ac.kr

  12. FileInputStream/ FileOutputStream dishin@dcslab.snu.ac.kr

  13. Standard I/O • 운영체제가 제공하는 기능에 의해 프로그램의 수정없이 다양한 입출력 장치(keyboard, monitor ,file)로 입출력 제공 • 표준 입출력 객체 • InputStream System.in • Standard input stream (default 로 keyboard) • OutputStream System.out • Standard output stream (default로 monitor ) • PrintStream System.err • Standard error stream (default로 monitor) dishin@dcslab.snu.ac.kr

  14. Standard I/O • result dishin@dcslab.snu.ac.kr

  15. Reader/Writer • Input source로 부터 Unicode 문자 자료(char, char[], string)을 읽어들이고 제어할 수 있는 method를 제공하는 abstract character input/output stream class • FileReader/FileWriter : FileInputStream , FileOutputStream과 기능이 거의 동일 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) dishin@dcslab.snu.ac.kr

  16. InputStreamReader/OutputStreamWriter • Byte stream 을 Character stream과 연결시켜 Unicode 문자를 입출력 할 수 있다. • Byte stream의 문자 인코딩을 지정. dishin@dcslab.snu.ac.kr

  17. InputStreamReader/OutputStreamWriter dishin@dcslab.snu.ac.kr

  18. Memory Stream dishin@dcslab.snu.ac.kr

  19. Memory Stream dishin@dcslab.snu.ac.kr

  20. I/O 관련 기본 exception class • java.io 및 java.net package의 모든 exception class는 java.io.IOException의 extended class • 따라서 IOException handling 만으로 모두 처리가능 dishin@dcslab.snu.ac.kr

  21. Next • 입출력 기능에 따른 stream class(filtering) • Buffering, string presentation… • Object stream • 객체 직렬화( Serializable interface ) dishin@dcslab.snu.ac.kr

More Related