Java-Explicitly Throw IOException

Explicitly Throw IOException In the following program, the main( ) method declares that it throws IOException and therefore we need not use try……….catch statements. I/O exceptions explicitly thrown out of main( ), this method likely to generate exceptions types of I/O exceptions. Instead of handling this object by itself, this method instructs its caller(JVM) to handle this … Read more…

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(“Honda-Japan.jpg”); fo = new FileOutputStream(“Honda-Japan2.jpg”); int getSize = fi.available(); System.out.println(“File Size : “+getSize); int i = 0; int getByte; while(i<getSize) { getByte = fi.read(); fo.write(getByte); … 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. Program   Binary File Byte stream classes are … 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…

Java-BufferedWriter

BufferedWriter The BufferedWriter class possesses the functionality of writing buffers of characters into a file. In the following program, an object of FileWriter class is first created and associated with the data file output.txt. Then, an object of BufferedWriter class is created. Subsequently, the names of five national parks are stored in the data file … Read more…