파일을 byte하나씩 받기
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class FileStreamTest {
public static void main(String[] args) {
FileInputStream fi = null;
try {
//1. 연결
fi = new FileInputStream("D:\\Desert.jpg");//연결
//2. I/O작업(읽는 작업)
int data = fi.read();//1바이트
int count =0;
long l1 = System.currentTimeMillis();//시간 계산
while(data!=-1){
count++;
data = fi.read();
}
long l2 = System.currentTimeMillis();//시간 계산
System.out.println("읽은 횟수 : "+count);
System.out.println((l2-l1)/1000+"초");
//3. 연결 끊기
//fi.close();//연결 끊기
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
if(fi!=null){//만약 fi가 null이 아닐 경우
try {
fi.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}