▶ Byte File Copy
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class ByteFileCopy {
public static void main(String[] args) throws IOException {
InputStream in = new FileInputStream("org.bin");
OutputStream out = new FileOutputStream("cpy.bin");
int copyByte = 0;
int bData = 0;
while(true) {
bData = in.read();
if(bData == -1)
break;
out.write(bData);
copyByte++;
}
in.close();
out.close();
System.out.print("복사된 바이트 크기 " + copyByte);
}
}
▶ Buffer File Copy
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class BufferFileCopy {
public static void main(String[] args) throws IOException {
InputStream in = new FileInputStream("org.bin");
OutputStream out = new FileOutputStream("cpy.bin");
int copyByte = 0;
int readLen;
byte buf[] = new byte[1024];
while(true) {
readLen = in.read(buf);
if(readLen == -1)
break;
out.write(buf, 0, readLen);
copyByte += readLen;
}
in.close();
out.close();
System.out.println("복사된 바이트 크기 " + copyByte);
}
}
[Java]FileReader & FileWriter (0) | 2012.09.28 |
---|---|
[Java]필터 스트림 (0) | 2012.09.24 |
[Java] wait, notify, notifyAll에 의한 실행순서 동기화 (0) | 2012.09.21 |
[Java]동기화 기법 예제. (0) | 2012.09.20 |
[Java]Thread 예제 (0) | 2012.09.17 |
댓글 영역