(http://www.yunsobi.com/blog/406)
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class StreamCopy {
public void copy(String source, String target) {
File sourceFile = new File(source);
FileInputStream inputStream = null;
FileOutputStream outputStream = null;
try {
inputStream = new FileInputStream(sourceFile);
outputStream = new FileOutputStream(target);
int byteRead = 0;
byte[] buffer = new byte[1024];
while((byteRead = inputStream.read(buffer, 0, 1024))!=-1) {
outputStream.write(buffer, 0, byteRead);
}
} catch(Exception e) {
e.printStackTrace();
} finally {
try {
outputStream.close();
} catch(IOException ioe) {
}
try {
inputStream.close();
} catch(IOException ioe) {
}
}
}
}
'Java Programming' 카테고리의 다른 글
static 변수 garbage collection (0) | 2010.07.14 |
---|---|
Java Compiler Generating Secret Methods (0) | 2010.07.06 |
Handling memory leaks in Java programs (0) | 2010.03.29 |
ArrayList 에서 String[] 변환 (0) | 2009.11.03 |
static initializer & instance initializer (0) | 2009.07.23 |