Java-Reading and Writing Raw Binary Files

Program

Program Source

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

class Javaapp {
    
    public static void main(String[] args) {
        
        FileInputStream fi = null;
        FileOutputStream fo = null;
        
        try{
            fi = new FileInputStream("lion.jpg");
            fo = new FileOutputStream("lion2.jpg");
            int getSize = fi.available();
            
            int i = 0;
            while(i<getSize)
            {
                fo.write(fi.read());
                i++;
            }
        }catch(IOException io)
        {
            System.out.println("Exception : "+io);
            
        }finally{
            
            try{
                fo.close();
                fi.close();
                
            }catch(IOException io)
            {
                System.out.println("Exception : "+io);
            }
        }
    }
}

Leave a Comment