바이트(Byte) 기반 입력 스트림의 최상위 클래스로 추상 클래스이다.
int read(byte[] buf) throws IOException
InputStream is = new FileInputStream("C:/test.jpg");
int readByteNo;
byte[] readBytes = new byte[100];
while((readByteNo = is.read(readByte)) != -1) {
...
}
int read(byte[] buf, int off, int len) throws IOException
InputStream is = ...;
byte[] readBytes = new byte[100];
int readByteNo = is.read(readBytes, 0, 100);
바이트(Byte) 기반 출력 스트림의 최상위 클래스로 추상 클래스이다.
void write(byte[] buf) throws IOException
OutputStream os = new FileOutputStream("C:/test.text");
byte[] data = "ABC".getBytes();
os.write(data) // "ABC" 모두 출력
void write(byte[] buf, int off, int len) throws IOException
OutputStream os = new FileOutputStream("C:/test.txt");
byte[] data = "ABC".getBytes();
os.write(data, 1, 2); // "BC" 출
문자 기반 입력 스트림의 최상위 클래스로 추상 클래스이다.
int read() throws IOException
char charData = (char) read();
Reader reader = new FileReader("C:/test.txt");
int readData;
while ((readData = reader.read()) != -1){
char charData = (char) readData;
}
int read(byte[] cbuf) throws IOException
Reader reader = new Reader("C:/test.txt");
int readCharNo;
char[] cbuf = new char[2];
while ((readCharNo = reader.read(cbuf)) != -1){
...
}
abstract int read(byte[] cbuf, int off, int len) throws IOException
Reader reader = ...;
byte[] cbuf = new cbuf[100];
int readCharNo = reader.read(cbuf, 0, 100);
문자 기반 출력 스트림의 최상위 클래스로 추상 클래스이다.
void write(int c) throws IOException
Writer writer = new FileWriter("C:/test.txt");
char[] data = "홍길동".toCharArray();
for(int i = 0; i < data.length; ++i){
writer.write(data[i]); // "홍", "길", "동"을 하나씩 출력
}
void write(char[] cbuf) throws IOException
Writer writer = new FileWriter("C:/test.txt");
char[] data = "홍길동".toCharArray();
writer.write(data); // "홍길동" 모두 출력
abstract void write(char[] cbuf, int off, int len) throws IOException
Writer writer = new FileWriter("C:/test.txt");
byte[] cbuf = new cbuf[100];
writer.write(data, ); // "홍길동" 모두 출력