반응형
package dayday18;
/*
* 기타 파일 (jpeg, avi...등 ) 에 대한 스트림
* - FileInputStream
* - FileOutputStream
*/
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
class Timer extends Thread {
@Override
public void run() {
int i = 1;
while (true) {
try {
System.out.println((i++) + "초 경과");
Thread.sleep(1000);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// TODO Auto-generated method stub
}
}
public class test03 {
public static void main(String[] args) {
/*
* Koala.jpg를 copied.jpg에 복사하는 프로그램
*/
FileInputStream in;
FileOutputStream out;
Timer t = new Timer();// 객체화
// InputMess ii = new InputMess();
// t,i를 데몬스레드로 설정
t.setDaemon(true);
// ii.setDaemon(true);//이러면 스레드가 돌지않고 끝난
t.start(); // 실제 실행시 사용
try {
//in = new FileInputStream("koala.jpg");
in = new FileInputStream("Wildlife.wmv");
//out = new FileOutputStream("copied.jpg");
//2초 경과
out = new FileOutputStream("Wildlife_copied.wmv");
//44초 경과
/*
* 복사시작
* InputStream의 read()
* - 스트림의 1byte를 꺼내어 int형으로 반환
* - 스트림이 비어있으면(EOF/End Of File) -1을 반환
* OutputStream의 write()
* - 써라!
*/
while(true){
int data = in.read();
if(data == -1){
break;
}
out.write(data);
}
System.out.println("복사끝");
in.close();
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
반응형
'IT > Programming' 카테고리의 다른 글
[JAVA] File Class 사용 예제 (0) | 2023.04.20 |
---|---|
[JAVA] 텍스트파일을MessageDialog으로 출력 (0) | 2023.04.20 |
[JAVA] ObjectOutputStream,InputStream 사용 예제 (0) | 2023.04.20 |
[JAVA] 파일 객체정보 읽어들이기 (0) | 2023.04.20 |
[JAVA] 동영상 복사 + 시간경과 사용 예제 (0) | 2023.04.20 |