Share on Google+Share on Google+

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

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

Ads

View Answers

December 23, 2010 at 1:16 PM


Hello Friend,

Try the following code:

import java.io.*;
import java.util.*;
class DisplayContentOfFile
{
    public static void main(String[] args) throws Exception
    {
        Scanner input=new Scanner(System.in);
        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="";
        while((line=br.readLine())!=null){
            System.out.println(line);
        }
    }
}

Thanks










Related Tutorials/Questions & Answers:
io
io
Advertisements
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 java.io.*; 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
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. java.io.FileReader 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. java.io.PipedWriter writes the characters to the piped output stream. Characters written to the piped output stream can be read by the corresponding
Java IO CharArrayReader
Java IO CharArrayReader In this tutorial we will learn about the CharArrayReader class in Java. CharArrayReader class in java.io package provides the facility to read the character input stream from char array. Input stream
Tutorials   
Java Spring Hibernate Struts Training Retrieve database from the table dynamically in jsp from oracle using servlet What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? neo4j-server.properties file location SASLError using PLAIN: not-authorized

Ads

 
Advertisement null

Ads