본문 바로가기

Java SE/FileInputTest

FileInputTest

스트림을 이용하여 파일을 크기를 출력하는 예

import java.io.*;

class  FileInputTest {
 public static void main(String[] args) throws IOException {

  FileInputStream fin = new FileInputStream("flower.jpg");

  int read = 0;
  int total = 0;

  byte[] buf = new byte[1024];

  while((read=fin.read(buf))!= -1) {
   total += read;
  }

  fin.close();

  System.out.println("총:"+total +" bytes");
 }
}