728x90 AdSpace

Tuesday, 1 October 2013

Reading the file using FileInputStream

In this tutorials we are going to see how to read file using FileInputStream.
  1. Create project called JavaMisc.
  2. Create package called com.javatutorialscorner.io
  3. Create java class called FileReader under com.javatutorialscorner.io package.
package com.javatutorialscorner.io;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class FileReader {

public static void main(String[] args) {
File file = new File("C:\\jtc\\javatutorialscorner.txt");
FileInputStream fin = null;
int templine;
try {
fin = new FileInputStream(file);

while ((templine = fin.read()) != -1) {
System.out.print((char) templine);

} catch (IOException e) {
} finally {
try {
if (fin != null) {
} catch (IOException e) {
// TODO Auto-generated catch block



Now run the program see the following output in console.

this is test file created by java tutorials corner

This content read from input file
Annamalai Thangaraj

Annamalai is working as Technical Lead in Leading Telecom company with 5+ years experience in Identity and Access Management , Telecom and Networks, BigData, Java, Spring, Struts, Hibernate, AngularJS, and Enterprise Web Application Development.

Website: Java Tutorials Corner

Shop and help us

Flipkart Offer Snapdeal offer Amazon.in offer Amazon.com offer
  • Blogger Comments
  • Facebook Comments
  • Disqus Comments


Post a Comment

Item Reviewed: Reading the file using FileInputStream Rating: 5 Reviewed By: Annamalai Thangaraj