Share on Google+Share on Google+

1 Answer(s)      6 years and 6 months ago
Posted in : Java Beginners

write a program in java to accept a filename from user and print its content on the monitor

View Answers

December 23, 2010 at 1:16 PM

Hello Friend,

Try the following code:

import java.util.*;
class DisplayContentOfFile
    public static void main(String[] args) throws Exception
        Scanner input=new Scanner(;
        System.out.println("Enter file: ");
        String str=input.nextLine();
        File file=new File(str);
        FileReader fr=new FileReader(file);
        BufferedReader br=new BufferedReader(fr);
        String line="";



Related Tutorials/Questions & Answers:
IO concept
IO concept  Write a java program that moves the contents of the one file to another and deletes the old file.   Hi Friend, Try the following code: import*; class MoveFile{ public static void main(String
IO in java
IO in java  Your search mechanism will take as input a multi-word query and will return a list of documents where the given words appear. 1. Your score for this portion of the assignment will be based on the intelligence of your
java io - Java Beginners
Java IO Streams  What is the Java IO Stream
io packages - Java Beginners
io packages  How can I add two integers in java using io pacages
java IO programing
java IO programing  how Java source file is used as input the program will echo lines
IO File - Java Beginners
IO File  Write a java program which will read an input file & will produce an output file which will extract errors & warnings. It shall exclude the standard errors & warnings. The standard errors & warnings you can find out
java binary file io example
java binary file io example  java binary file io example
java-io - Java Beginners
java-io  Hi Deepak; down core java io using class in myn code twodimensional arry is not supportin. veryfy my code ... how can i modify this code. Thank you. RameshReddy T
Import java IO - Java Beginners
Import java IO  for example i know java IO is for input and output. I am using Netbeans5.5.1. How can i see all the classes related to java IO for example; stream reader, buffer reader
Simple IO Application - Java Beginners
Simple IO Application  Hi, please help me Write a simple Java application that prompts the user for their first name and then their last name. The application should then respond with 'Hello first & last name, what
Maven dependency for Apache Commons IO
Maven dependency for Apache Commons IO  Hello, I need maven dependency for apache commons io. I have to add it to pom.xml file. Thanks   Hi, Here is the code which you can add it to pom.xml file: <dependency>
Java IO Path
Java IO Path In this section we will discuss about the Java IO Path. Storage of a file or folder(Directory/Subdirectory) in a Hard Drive or other media is called a Path of that file or folder using which they can be accessed easily
How to add Apache Commons IO in pom.xml file?
How to add Apache Commons IO in pom.xml file?  Hi, How to add the dependency of the Apache Commons IO library in the pom.xml file in a Java project? My Project is using the maven for dependency management and compilation
Spring IO Platform 1.0.0 Released
Spring IO Platform 1.0.0 Released - Check the new features of this release The Spring IO is platform for developing and building the modern day applications.... The Spring IO is 100% open source system and it is modular. The latest version
Difference between Java IO Class - Java Beginners
Difference between Java IO Class  What is the difference in function between Two set of Stream class as mention below- 1)FileInputStream & FileOutPutStream vs. 2)InputStreamReader & OutputStreamWriter
core java ,io operation,calling methods using switch cases
core java ,io operation,calling methods using switch cases  How to create a dictionary program,providing user inputs using io operations with switch cases and providing different options for searching,editing,storing meanings
Creating a File I/O using import scanner, io.* and text.*
Creating a File I/O using import scanner, io.* and text.*  open a file for reading and open another file for writing data. input file hours-int, hourly rate-double, name-string. output file name-string, hours-int, hourly rate
How to read the data in text file seperated by by ',' in java using IO Operations
How to read the data in text file seperated by by ',' in java using IO Operations  in Text file data like raju 45,56,67 ramu 46,65,78 raji 34,23,56 this is the student marks in text file.this data read and calculate
Java IO FilterWriter
Java IO FilterWriter In this example we will discuss about the FilterWriter... classes of IO package such as BufferedWriter (to write into the stream from buffer...(); bw.write("Java IO FilterWriter Example"); System.out.println("Data is written
Java IO StringReader
Java IO StringReader In this section we will discuss about the StringReader class in Java. StringReader class reads the string from the input stream...; String str = "\n Java IO StringReader \n"; try
Java IO OutputStreamWriter
Java IO OutputStreamWriter In this section we will learn about the Java..."); osw = new OutputStreamWriter(os); osw.write("Java IO..."); bw.newLine(); bw.write("Java IO OutputStreamWriter Example
Java IO FileReader
Java IO FileReader In this tutorial we will learn about the FileReader class in Java. class is used to read the character streams. To read the streams FileInputStream can be considered. This class extends
Java IO PipedWriter
Java IO PipedWriter In this tutorial we will learn about the PipedWriter in Java. writes the characters to the piped output stream. Characters written to the piped output stream can be read by the corresponding