Advertisements
Home > Java > Java Program to read data from a file through inputfilestream and show it on the console. – Q34

Java Program to read data from a file through inputfilestream and show it on the console. – Q34


Q34: Java Program to read data from a file through inputfilestream and show it on the console.

import java.io.*;
import javax.swing.*;

class File_read{

	public static void main(String args[]) throws IOException{
		
		String f_name = JOptionPane.showInputDialog("Enter a File name: ");
		
		File f = new File(f_name);
		InputStream file = new FileInputStream(f);
		
		int fsize = file.available();
		
		System.out.println("Reading File : " + f.getName() + "\n");
		
		for(int i=0; i<fsize; i++)
			System.out.print((char)file.read());
	}
}

… from College notes (BCA/MCA assignments):


Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: