Results 1 to 6 of 6
  1. #1
    okokok is offline Member
    Join Date
    Sep 2011
    Posts
    21
    Rep Power
    0

    Default Why I get the result is NULL

    import java.io.*;
    import java.util.*;
    class reader {
    public static void main(String args[]) throws Exception {


    FileReader fr = new FileReader("C:\\Users\\huang783\\workspace\\Interp \\input.txt");

    BufferedReader br = new BufferedReader(fr);
    int Counter=0;
    Scanner input = new Scanner(fr);
    while(input.hasNextLine())
    {
    String line = input.nextLine();
    Counter++;
    }

    String[] memory= new String[4];


    for (int j = 0; j < memory.length; j++){
    memory[j] = br.readLine();
    System.out.println(memory[j]);
    }
    Why I get the result is NULL-.jpg

    and my input is
    Why I get the result is NULL-.jpg


    why?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Why I get the result is NULL

    You've already iterated fully through the FileReader with the Scanner object so the FileReader pointer is now at the end of the file when you try to read it with the BufferedReader. I'm not not surprised at your result.

  3. #3
    okokok is offline Member
    Join Date
    Sep 2011
    Posts
    21
    Rep Power
    0

    Default Re: Why I get the result is NULL

    how can i fix it ?
    Quote Originally Posted by Fubarable View Post
    You've already iterated fully through the FileReader with the Scanner object so the FileReader pointer is now at the end of the file when you try to read it with the BufferedReader. I'm not not surprised at your result.

  4. #4
    okokok is offline Member
    Join Date
    Sep 2011
    Posts
    21
    Rep Power
    0

    Default Re: Why I get the result is NULL

    I just add the input.close(), but still has exception.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Why I get the result is NULL

    You need a new FileReader for each wrapper class that needs one.

  6. #6
    okokok is offline Member
    Join Date
    Sep 2011
    Posts
    21
    Rep Power
    0

    Default Re: Why I get the result is NULL

    Do you have another method like reset()? no new FileReader?

Similar Threads

  1. Keep getting result of 0.
    By dookie1293 in forum New To Java
    Replies: 7
    Last Post: 06-09-2011, 06:01 AM
  2. Struts 2 error : No result defined for action / result
    By sameerk in forum Web Frameworks
    Replies: 1
    Last Post: 05-17-2011, 11:15 AM
  3. How to return a null result??
    By Yakg in forum New To Java
    Replies: 6
    Last Post: 12-07-2010, 09:38 PM
  4. Replies: 6
    Last Post: 10-18-2010, 11:40 AM
  5. Replies: 2
    Last Post: 03-19-2010, 06:30 PM

Posting Permissions

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