Read a text block by block using InputStream and FileInputStream - Java File Path IO

Java examples for File Path IO:FileInputStream

Description

Read a text block by block using InputStream and FileInputStream

Demo Code


import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

public class InputStreamTest {
    public static void main(String[] args) throws IOException{
        InputStream inputStream = null;
        try{//  w  w w .  jav a  2s. c o  m
            inputStream = new FileInputStream("C:/input.txt");
            byte[] bytes = new byte[1024];
            int index;
            while((index = inputStream.read(bytes)) != -1){
                System.out.println("index ="+index);
            }
        }finally{
            if(inputStream != null){
                inputStream.close();
            }
        }
    }
}

Related Tutorials