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

Slides:



Advertisements
Similar presentations
A Guide to Advanced Java Faculty:Nguyen Ngoc Tu. 2 Operating System Application #1 Application #2 Java Virtual Machine #1 Local Memory Shared Memory Threads.
Advertisements

1 Streams and Input/Output Files Part 2. 2 Files and Exceptions When creating files and performing I/O operations on them, the systems generates errors.
1 Streams and Input/Output Files Part I. 2 Introduction So far we have used variables and arrays for storing data inside the programs. This approach poses.
Jan Java I/O Yangjun Chen Dept. Business Computing University of Winnipeg.
Streams Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from.
Geoff Holmes Overview IO Zoo Stream I/O File I/O Buffering Random-Access Text Streams Examples Serialization Java IO – programs that start with import.
Streams and Files The objectives of this chapter are: To understand the principles of I/O streams and where to use them To understand the options and limitations.
Java I/O and Java Networking (Client Side) Yoshi.
Overview of Java I/O. Stream A Program often needs to read/write information from/to outer source/destination. Outer source/destination can be : –A File.
Algorithm Programming I/O via Java Streams Bar-Ilan University תשס"ח by Moshe Fresko.
Exceptions and IO Dr. Andrew Wallace PhD BEng(hons) EurIng
Java I/O Input: information brought to program from an external source
Java Programming: I/O1 Java I/O Reference: java.sun.com/docs/books/tutorial/essential/io/
CS203 Programming with Data Structures Input and Output California State University, Los Angeles.
Java How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Input and Output F Stream Classes F Processing External Files F Data Streams F Print Streams F Buffered Streams F Text Input and Output on the Console.
Streams Reading: 2 nd Ed: , rd Ed: 11.1, 19.1, 19.4
Java How to Program, 8/e © by Pearson Education, Inc. All Rights Reserved.
Richiami di Java Input/Output. import java.io.*; public class Simple { public static void main(String a[]){ new Simple(); } public Simple() { byte buffer[]=new.
JAVA I/O © EnhanceEdu, IIIT Hyderabad. Contents 3/29/2010EnhanceEdu, IIIT - H 2  Command Line I/O  File Class  Streams  Byte Streams [Low level and.
Java Programming: Advanced Topics 1 Input/Output and Serialization Chapter 3.
Java Input/Output CSE301 University of Sunderland Harry Erwin, PhD Half Lecture.
Input/output Input in java is stream based.A stream represents sequence of bytes or characters. Stream provides an abstract view of I/O. Stream can be.
L5: Input & Output COMP206, Geoff Holmes and Bernhard Pfahringer.
Java Input/Output. Reading standard input Surprisingly complicated (GUI focus) Old-fashioned way: BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
Introduction to Computation and Problem Solving Class 29: Introduction to Streams Prof. Steven R. Lerman and Dr. V. Judson Harward.
1 Software 1 Java I/O. 2 The java.io package The java.io package provides: Classes for reading input Classes for writing output Classes for manipulating.
1 OOP Lecture 17 I/O and Graphics Signe Ellegård Borch Carsten Schuermann IT University Copenhagen.
CS 116 OBJECT ORIENTED PROGRAMMING II LECTURE 11 GEORGE KOUTSOGIANNAKIS Copyright: 2015 / Illinois Institute of Technology/George Koutsogiannakis 1.
CSI 3125, Preliminaries, page 1 Java I/O. CSI 3125, Preliminaries, page 2 Java I/O Java I/O (Input and Output) is used to process the input and produce.
Company Input/Output Stream –. Input/Output Stream Data Program Input Stream Output Stream.
DEPARTMENT OF COMPUTER SCIENCE N.HARIKA. Contents Overview of I/O Streams Character Streams Byte Streams Using the Streams 2.
Exception Handling, Reading and Writing in Files, Serialization, Exceptions, Files, Streams, File Readers and Writers, Serializable SoftUni Team Technical.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 13 Java Fundamentals File I/O Serializing an.
1 Putting Streams to use. 2 Stream Zoo C++ gives you istream, ostream, iostream, ifstream, ofstream, fstream, wistream, wifstream, istrsteam… (18) Java.
Java Input / Output l a modular approach to input/output: - different stream objects are connected/wrapped to handle I/O l a data stream object: a flow.
Java Programming: Advanced Topics 1 Input/Output and Serialization.
Java I/O 1. Java I/O (Input and Output) is used to process the input and produce the output based on the input. The java.io package contains all the classes.
CS202 Java Object Oriented Programming Input and Output Chengyu Sun California State University, Los Angeles.
Generics and file handling Presented by: Abha Kumari Neha Pradip Vhanmane Raj Visa Rashmi Kewlani Suvrat Dixit.
Chapter 10: I/O Streams Input Streams Output Streams
The Java IO System Different kinds of IO Different kinds of operations
CSC1351 Class 6 Classes & Inheritance.
Keerthi Nelaturu Url: site.uottawa.ca/~knela006
Fundamental of Java Programming
IO in java.
Sequential files creation & writing
Lecture 8: I/O Streams types of I/O streams Chaining Streams
Java Text I/O CS140 Dick Steflik. Reader Abstract super class for character based input Subclasses: – BufferedReader – CharArrayReader – FilterReader.
IO in java.
Exception Handling, Reading and Writing in Files, Serialization,
Ch14 Files and Streams OBJECTIVES
Chapter 8: Input and Output
Object Writing in files
12: The Java I/O System stream model.
8/30/2018 CPRG 215 Introduction to Object-Oriented Programming with Java Module 5- The java.io Package Topic 5.1 Input and Output Streams, Readers.
I/O Basics.
תרגול מס' 5: IO (קלט-פלט) זרמי קלט וזרמי פלט ((Input & Output Streams,
Programming in Java Files and I/O Streams
Објектно орјентисано програмирање
Java’s Hierarchy Input/Output Classes and Their Purpose
JAVA IO.
תרגול מס' 5: IO (קלט-פלט) זרמי קלט וזרמי פלט ((Input & Output Streams,
Stream Oriented I/O Computer Programming II Dr. Tim Margush
Input and Output Stream
CSC 143 Java Streams.
OBJECT ORIENTED PROGRAMMING II LECTURE 20 GEORGE KOUTSOGIANNAKIS
Files and Streams in Java
David Davenport Spring 2005
Presentation transcript:

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

Stream Stream? Why JAVA uses Stream? 대부분의 method는 throws IOException 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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Memory Stream dishin@dcslab.snu.ac.kr

Memory Stream dishin@dcslab.snu.ac.kr

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

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