Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- takanaru
- 로니세라
- 랍스터 찜
- 응용 프로그램 내 구입
- 신주쿠 로컬식당
- 10 올림
- 코로나백신 갈증
- cisco vpn
- 크롬 인터넷연결
- 10원단위 올림
- Windows10
- 코로나백신 어지러움
- 윈도우10 vpn
- windows10 크롬
- 코로나백신
- 타카마루
- 강화 프로방스
- 코로나백신이상증상
- 크롬 타임아웃
- 분기날짜
- 화이자백신
- 노리로또
- windows10 cisco vpn
- 핸드폰 찾기
- 오라클
- 신주쿠맛집
- 크롬 인너넷연결 안됨
- 안드로이드폰 위치
- 코로나백신 부작용
- 성수족발
Archives
- Today
- Total
이거 맘대로 되는 세상이 아니구만...
Stream7(파일복사) 본문
반응형
▶ 파일명 복사하기
FileInputStream과 FileOutputStream을 이용해도 되고 FileReader와 FileWriter을 사용해도 된다.
FileInputStream fis=new FileInputStream("원본파일복사"); //파일위치의 경로를 지정해줘야 한다
FileOutputStream fis1=new FileInputStream("복사파일명")
import java.io.*;
public class kkk{
public static void main(String args[])throws IOException{
int i,len=0;
FileInputStream fis=new FileInputStream(args[0]);
FileOutputStream fis1=new FileOutputStream(args[1]);
long psecond=System.currentTimeMillis();
while((i=fis.read())!=-1){ //입력스티림에서 한 바이트씩 읽고 출력 스트림으로 바로 내보내기
fis1.write(i);
len++;
}
fis.close();
fis1.close();
psecond=System.currentTimeMillis()-psecond; //파일을 복사하는 시간을 측정
System.out.println(len+"byte "+psecond+"miliseconds");
}
}
▶Buffered 스트림을 이용한 파일복사 예제
import java.io.*;
public class kkk{
public static void main(String args[])throws IOException{
int i,len=0;
FileInputStream fis=new FileInputStream(args[0]);
FileOutputStream fis1=new FileOutputStream(args[1]);
BufferedInputStream bis=new BufferedInputStream(fis);
BufferedOutputStream bis1=new BufferedOutputStream(fis1);
long psecond=System.currentTimeMillis();
while((i=bis.read())!=-1){
bis1.write(i);
len++;
}
bis.close();
bis1.close();
psecond=System.currentTimeMillis()-psecond;
System.out.println(len+"byte "+psecond+"miliseconds");
}
}
●위 두 로직의 결과를 보면 Buffered스트림이 빠른시간에 파일 복사가 되는 것을 확인 할 수 있다
보통의 경우 스트림을 이용한다면 Buffered 스트림으로 변화해서 처리하는것이 좋다
FileInputStream과 FileOutputStream을 이용해도 되고 FileReader와 FileWriter을 사용해도 된다.
FileInputStream fis=new FileInputStream("원본파일복사"); //파일위치의 경로를 지정해줘야 한다
FileOutputStream fis1=new FileInputStream("복사파일명")
import java.io.*;
public class kkk{
public static void main(String args[])throws IOException{
int i,len=0;
FileInputStream fis=new FileInputStream(args[0]);
FileOutputStream fis1=new FileOutputStream(args[1]);
long psecond=System.currentTimeMillis();
while((i=fis.read())!=-1){ //입력스티림에서 한 바이트씩 읽고 출력 스트림으로 바로 내보내기
fis1.write(i);
len++;
}
fis.close();
fis1.close();
psecond=System.currentTimeMillis()-psecond; //파일을 복사하는 시간을 측정
System.out.println(len+"byte "+psecond+"miliseconds");
}
}
▶Buffered 스트림을 이용한 파일복사 예제
import java.io.*;
public class kkk{
public static void main(String args[])throws IOException{
int i,len=0;
FileInputStream fis=new FileInputStream(args[0]);
FileOutputStream fis1=new FileOutputStream(args[1]);
BufferedInputStream bis=new BufferedInputStream(fis);
BufferedOutputStream bis1=new BufferedOutputStream(fis1);
long psecond=System.currentTimeMillis();
while((i=bis.read())!=-1){
bis1.write(i);
len++;
}
bis.close();
bis1.close();
psecond=System.currentTimeMillis()-psecond;
System.out.println(len+"byte "+psecond+"miliseconds");
}
}
●위 두 로직의 결과를 보면 Buffered스트림이 빠른시간에 파일 복사가 되는 것을 확인 할 수 있다
보통의 경우 스트림을 이용한다면 Buffered 스트림으로 변화해서 처리하는것이 좋다
Comments