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{ … Read more…

Java-FileOutputStream

FileOutputStream FileOutputStream class possesses the functionality of writing one byte at a time into a file. In the following program, a data file named data.da is associated with an object of FileOutputStream class. Then, byte array by is written into the data file data.da. Finally, the file data.da is closed. FileOutputStream Constructors Constructors Description FileOutputStream(String name) Creates a file … Read more…

Java-BufferedReader

BufferedReader The BufferedReader class possesses the functionality of reading buffers of characters from a file. In the following program, an object of FileReader class is first created and associated with the data file output.txt. Then, an object of BufferedReader class is created. Subsequently, the names of five national parks, which have been written into the … Read more…