sitelink1 | |
---|---|
sitelink2 | |
sitelink3 | |
sitelink4 | |
sitelink5 | |
sitelink6 |
1. java.io 패키지 이용
2. java.nio 패키지 이용
·미리보기 | 소스복사·
- public void copyFile(File in, File out) throws Exception {
- File parent = out.getParentFile();
- if (!parent.exists()) {
- parent.mkdir();
- }
- FileInputStream fis = new FileInputStream(in);
- FileOutputStream fos = new FileOutputStream(out);
- byte[] buf = new byte[1024];
- int i = 0;
- while ((i = fis.read(buf)) != -1) {
- fos.write(buf, 0, i);
- }
- fis.close();
- fos.close();
- }
2. java.nio 패키지 이용
·미리보기 | 소스복사·
- public void copyFile(File in, File out) throws Exception {
- File parent = out.getParentFile();
- if (!parent.exists()) {
- parent.mkdir();
- }
- FileChannel sourceChannel = new FileInputStream(in).getChannel();
- FileChannel destinationChannel = new FileOutputStream(out).getChannel();
- sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
- sourceChannel.close();
- destinationChannel.close();
- }