대상 파일: a.pptx
사본 이름: d.pptx
public class Study59 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("대상 파일: ");
String src = sc.nextLine();
System.out.print("사본 이름: ");
String dst = sc.nextLine();
try(BufferedInputStream in = new BufferedInputStream(new FileInputStream(src));
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(dst))) {
int data;
while(true) {
data = in.read();
if(data == -1)
break;
out.write(data);
}
}
catch(IOException e) {
e.printStackTrace();
}
}
}
자바에서 제공하는 보조 스트림은 실제로 데이터를 주고받을 수는 없지만, 다른 스트림의 기능을 향상시키거나 새로운 기능을 추가해 주는 스트림이다.
자바에서는 다음과 같은 다양한 보조 스트림을 제공하고 있다.
자바에서는 바이트 기반 스트림뿐만 아니라 문자 기반의 스트림도 별도로 제공 한다.
바이트 기반 스트림
자바에서 스트림은 기본적으로 바이트 단위로 데이터를 전송
1바이트씩 전송
문자 기반 스트림
자바에서 가장 작은 타입인 char 형이 2바이트로, 바이트 기반 스트림으로는 원활한 처리가 힘든 경우 문자 기반 스트림을 사용
기존의 바이트 기반 스트림에서 InputStream을 Reader로, OutputStream을 Writer로 변경하면 사용 가능