Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: TXT files

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Thanked 0 Times in 0 Posts

    Exclamation TXT files

    Hello everyone,

    I Would like to ask you 2 simple questions that I cannot answer by myself.

    1 I need to "import" a txt file to memory and then print it on screen.

    I have already done the first part. I is correct?

    2 How can I print the file to the screen?

    private static void leInfo(){
    LineNumberReader ficheiro;
    try {
    ficheiro = new LineNumberReader(new FileReader("Uvas.txt"));
    Scanner sc = new Scanner(ficheiro);

    String nome =sc.next();
    Regiao reg=Regiao.valueOf(sc.next());
    Qualidade qual=Qualidade.valueOf(sc.next());
    int quantidade=sc.nextInt();


    } catch (Exception e) {
    // TODO Auto-generated catch block

    Thank You very much

  2. #2
    Junior Member
    Join Date
    Sep 2010
    Thanked 0 Times in 0 Posts

    Default Re: TXT files

    A way you could do it is:

    Use a FileReader to read the file:
    FileReader fr = new FileReader("Uvas.txt");
    then you could use a BufferedReader to read the text on the file:
    BufferedReader br = new BufferedReader(fr);

    Then you could use a try-catch statement to read everything and print it out:
     try {
    String text;  //you make a new String for text
                            while ((text = br.readLine()) != null) {
                        } catch (IOException ex) {
                          System.out.println("this doesn't work because: " + ex);
                    } catch (FileNotFoundException ex) {
                        System.out.println(" not found :" + ex);

    Again, this isn't the way you do it. but it might help.

Similar Threads

  1. need help on jar files
    By kaka09 in forum AWT / Java Swing
    Replies: 2
    Last Post: July 13th, 2010, 09:30 AM
  2. hlp files
    By vgenopoulos in forum Java Theory & Questions
    Replies: 1
    Last Post: July 9th, 2010, 09:11 AM
  3. jar files
    By bguy in forum Java Theory & Questions
    Replies: 2
    Last Post: November 23rd, 2009, 06:37 PM
  4. exe files
    By subhvi in forum Java Theory & Questions
    Replies: 17
    Last Post: September 3rd, 2009, 09:43 AM