Results 1 to 7 of 7

Thread: Txt Files

  1. #1
    eldiablo3000 is offline Member
    Join Date
    Jan 2011
    Posts
    4
    Rep Power
    0

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

    while(sc.hasNext()){
    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
    e.printStackTrace();
    }
    }

    Thank You very much

  2. #2
    JavaHater is offline Senior Member
    Join Date
    Dec 2010
    Posts
    165
    Rep Power
    4

    Default

    2 How can I print the file to the screen?
    you can use System.out.println() , System.out.print(), System.out.printf() ......

  3. #3
    eldiablo3000 is offline Member
    Join Date
    Jan 2011
    Posts
    4
    Rep Power
    0

    Default

    System.out.print("uvas.txt")

    will this show on screen the content of the file?

    example:
    uvas.txt
    content:"
    (trincadeira douro boa 100)
    "

  4. #4
    JavaHater is offline Senior Member
    Join Date
    Dec 2010
    Posts
    165
    Rep Power
    4

    Default

    you have already done this
    Java Code:
    while(sc.hasNext()){
    String nome =sc.next();
    Regiao reg=Regiao.valueOf(sc.next());
    Qualidade qual=Qualidade.valueOf(sc.next());
    int quantidade=sc.nextInt();
    those variables contains the contents from the file already. All you have to do is print them out

  5. #5
    eldiablo3000 is offline Member
    Join Date
    Jan 2011
    Posts
    4
    Rep Power
    0

    Default

    but in main i did

    System.out.println("Uvas.txt");

    and appear "Uvas.txt" not the content

  6. #6
    JavaHater is offline Senior Member
    Join Date
    Dec 2010
    Posts
    165
    Rep Power
    4

    Default

    Quote Originally Posted by eldiablo3000 View Post
    but in main i did

    System.out.println("Uvas.txt");

    and appear "Uvas.txt" not the content
    that only prints the strin "Uvas.txt". you are already using a Scanner on Uvas.txt. so the variables that store the scanner inputs ( the ones i mentioned) are the data you need.

  7. #7
    eldiablo3000 is offline Member
    Join Date
    Jan 2011
    Posts
    4
    Rep Power
    0

    Default

    thanks

    so how can i print the variables stored by scanner?

Similar Threads

  1. Replies: 8
    Last Post: 07-30-2010, 05:47 PM
  2. import from dsv files and export to csv files
    By 10x2 in forum New To Java
    Replies: 12
    Last Post: 04-30-2010, 11:56 AM
  3. working with files (text files)
    By itaipee in forum New To Java
    Replies: 1
    Last Post: 02-24-2009, 11:38 AM
  4. Behaving text files like binary files
    By Farzaneh in forum New To Java
    Replies: 2
    Last Post: 08-27-2008, 03:20 PM
  5. Text and image files within jar files
    By erhart in forum Advanced Java
    Replies: 8
    Last Post: 01-19-2008, 04:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •