develog

java file copy test 본문

Dev/Java

java file copy test

냐옴 2012. 5. 24. 23:06

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.io.OutputStream;



public class TestMain {


public static void main(String[] args) {

System.out.println("START");

System.out.println("-----------------------------------");

fileCopyTest("assets/aa.zip", "assets/bb.zip");

fileCopyTest("assets/aa.txt", "assets/bb.txt");

fileCopyTest("assets/aa.jpg", "assets/bb.jpg");

fileCopyTest("assets/aa.xls", "assets/bb.xls");

fileCopyTest("assets/aa.ppt", "assets/bb.ppt");

fileCopyTest("assets/aa.docx", "assets/bb.docx");

fileCopyTest("assets/aa.swf", "assets/bb.swf");

System.out.println("-----------------------------------");

System.out.println("END");

}

private static void fileCopyTest(String sourceFile, String targetFile) {

InputStream in = null;

OutputStream out = null;

try {

in = new FileInputStream(sourceFile);

out = new FileOutputStream(targetFile);

byte[] buffer = new byte[1024];

int len = 0;

while ((len = in.read(buffer)) > -1) {

out.write(buffer, 0, len);

}

} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

} finally {

try {

if (out != null) out.close();

} catch (IOException e) {

}

try {

if (in != null) in.close();

} catch (IOException e) {

}

}

}

}


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

cmd 에서 jar 만들기  (0) 2012.06.13
줄바꿈 문자  (0) 2012.06.13
[java] Calendar, 1년전, 한달전, 하루전  (0) 2012.05.11
SimpleDateFormat  (0) 2012.05.10
Thread  (0) 2012.05.10
Comments