Java FileInputStream read() Example

FileInputStream class read() method example. This example shows you how to use read() method.


Syntax is : public int read() throws IOException
This method reads a byte of data from this input stream. This method blocks if no input is yet available.

Here is the code.
/**
 * @(#) ReadFileInputStream.java
 * A class representing use of method read() of FileInputStream 
class in java.io Package.
 * @Version  07-June-2008
 @author   Rose India Team
 */
import java.io.*;

public class ReadFileInputStream {
 
      public static void main(String[] argsthrows IOException {
          
        File file = new File("Mahendra.txt");
            byte[] b = new byte[]{'M','A','H','E','N','D','R','A','S','I','N'};
            FileOutputStream objFileOutStream = new FileOutputStream(file);
            objFileOutStream.write(b);
        
            // Create object of FileInputStream class.
        FileInputStream objFileInStream = new FileInputStream(file);

            System.out.print("Content of the file : ");
            forint i=0; i<b.length; i++) {
            System.out.print((char)objFileInStream.read());
            }
    }
}

output of the program.
Content of the file : MAHENDRASIN

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US