get bytes from fileoutputstream java code example

Example: fileinputstream read(byte[] b) example

package com.technicalkeeda;
import java.io.FileInputStream;
import java.io.IOException;
public class App {     
  public static void main(String[] args) {        
    try {  
      FileInputStream fileInputStream = new FileInputStream("C:\\technicalkeeda\\hello.txt");             
      byte[] bytes = new byte[16];           
      int i = fileInputStream.read(bytes);             
      System.out.println("Total bytes read :- " + i);             
      for (byte b: bytes) {                
        char c = (char) b;                
        System.out.print(c);            }             
      fileInputStream.close();  
    } 
    catch (IOException e) {           
      e.printStackTrace();       
    }   
  }
}

//  hello.txt contents is:
//  Hello TechnicalKeeda

//  output is: 
//  Total bytes read :- 16
// 
//  Hello TechnicalK

Tags:

Java Example