티스토리 뷰

public static void main(String[] args) throws IOException {
  long startTime = System.currentTimeMillis();
  String path = 파일경로;
//  String copyPath = 파일경로;
  String copyPath = 파일경로;
  //1차 스트림 파일장치에 직접 연결되면서 2차 스트림의 생성자로 주입이 될 스트림.
//  FileInputStream fis = null;
//  FileOutputStream fos = null;
  //2차스트림 중 Buffer의 기능을 가진 스트림을 사용하여 속도향상.
  BufferedInputStream bis = null;
  BufferedOutputStream bos = null;
  try {
//   fis = new FileInputStream(path);
//   fos = new FileOutputStream(copyPath);
   bis = new BufferedInputStream(new FileInputStream(path));
   bos = new BufferedOutputStream(new FileOutputStream(copyPath));
   int res = -1; //파일의 끝에 도달하면 -1반환
   while((res = bis.read()) != -1){ //읽어오는 메서드(read)
    bos.write(res); //읽어온 값을 작성하는 메서드(write)
   }
   bos.flush(); //버퍼를 비워주는 역할. 중요하다.
  } catch (FileNotFoundException e) {
   e.printStackTrace();
  } finally {
//   if(fis != null)fis.close();
//   if(fos != null)fos.close();
   if(bis != null)bis.close();
   if(bos != null)bos.close();
  }
  long endTime = System.currentTimeMillis();
  System.out.println("소요시간 : "+(endTime - startTime));
 }

 

'Back > Java' 카테고리의 다른 글

[JAVA] 이미지 리사이징  (0) 2017.08.03
[JAVA] I/O - URL클래스, PrintWriter  (0) 2016.02.03
[JAVA] I/O - FileInputStream, FileOutputStream (파일복사 예제)  (0) 2016.02.03
[JAVA] 배열  (0) 2013.11.30
[JAVA] LOG4J - 펌  (0) 2013.09.27
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2024/05   »
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
글 보관함