Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Read .txt file to a command line

Posted on 2005-03-03
9
Medium Priority
?
182 Views
Last Modified: 2010-03-31
Hi, I want to read the contents of a .txt file and print them to the command line. How do I do it in Java?
0
Comment
Question by:MPerre
6 Comments
 
LVL 16

Expert Comment

by:Joe
ID: 13456702
String line = null;
FileReader fr = null;
BufferedReader br = null;

fr = new FileReader("c:/mytxt.txt");
br = new BufferedReader(fr);

while ((line = br.readLine()) != null){
               System.out.println(line);

}

fr.close();
br.close();


Joe
0
 
LVL 30

Accepted Solution

by:
Mayank S earned 2000 total points
ID: 13456859
0
 

Author Comment

by:MPerre
ID: 13459038
Dosent work Joe. I need the complete code not just snipits.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 30

Expert Comment

by:Mayank S
ID: 13459171
It is against EE rules to ask for full code just like that. It is treated as homework no matter whether it is or not (read the member agreement). Come up with some coding efforts of your own and then we can help you more.
0
 
LVL 1

Expert Comment

by:sanjusk
ID: 13460688
Although i pasting the class file that does what you want. i don't know the urgency. But i agres what 'mayankeagle' says.

import java.io.*;

public class test{
  // Throw exceptions to console:
  public static void main(String[] args)
  throws IOException {
       BufferedReader in =
      new BufferedReader(
        new FileReader("IOStreamDemo.java"));
    String s, s2 = new String();
    while((s = in.readLine())!= null)
      s2 += s + "\n"; // System.out.println(s) -- whatever ever you like
    in.close();
    System.out.println(s2);
}
}
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses
Course of the Month12 days, 10 hours left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question