GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Saturday, December 18, 2010

Java IO - Reading A Binary File

To read a binary file, use:

import java.io.*;

public class Main{

    public static void main(String[] args){
        try{
            File file = new File("D://lady_gaga.jpg");
            FileInputStream input = new
                                    FileInputStream(file);       
            int biner = 0;
            while(biner!=-1){            // -1 is end of file
                biner = input.read();
                System.out.print(biner);
            }
        }catch(Exception ex){
            ex.printStackTrace();
    }
}
Share/Bookmark

No comments:

Post a Comment