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

January 17, 2009 Leave a comment Go to comments

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):


Advertisement
  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 )

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: