1 2 Previous Next 18 Replies Latest reply on Jul 9, 2007 9:26 AM by 807600 Go to original post
      • 15. Re: Need help with reading files
        807600
        which mean i learn from what i am doing wrong.
        honestly if you not trying to help a newbie out why
        you even bother to come to this section.
        All true. Now show us what you are made of. Think this through, and come up with a solution. You know you can do it. Then show it to us.

        Good luck.
        • 16. Re: Need help with reading files
          3004
          maybe i am in the wrong section of the forum,
          but
          i
          remember i post this in the "New To Java"
          section.
          New to Java != new to thinking, reading,
          investigating.
          which mean i learn from what i am doing wrong.
          Which I helpfully pointed out to you:

          * You didn't read promethuzz's answer closely enough.

          * You didn't read the docs.

          * You didn't stop and think and puzzle it through hard enough.

          honestly if you not trying to help a newbie out why
          you even bother to come to this section.
          If you think I'm not trying to help, you're mistaken. Just because you don't like what I say or how I say it doesn't mean I'm not being helpful.
          • 17. Re: Need help with reading files
            807600
            It gave me NoSuchElementException error ? may i know why?
            The API documentation says exactly why you get this exception.

            One thing you can do to get even more information is to catch the exception and print it out:
            try
            {
                while(sc.hasNext())
                {
                    sc.nextLine();
                    sc.nextLine();
                    line = sc.nextLine();
                    pw.println(line);
                } 
                pw.close();
            }
            catch(NoSuchElementException nsee)
            {
                nsee.printStackTrace();
            }
            It will print the "stack trace" which you read from the top down. The stack trace tells you exactly which line caused the problem. (As noted before, the problem being what the API documentation tells you the problem was.)

            If you have thought about but can't understand the stack trace, post it. Since the stack trace refers to line numbers (which we can't see) say which line of your code is being refered to.
            • 18. Re: Need help with reading files
              807600
                    if(sc.hasNextLine())
                         {
                              sc.nextLine();
                              sc.nextLine();
                              while(sc.hasNext())
                              {
                                  String line = sc.nextLine();
                                   firstPart = line.substring(0,19);
                                 secondPart = line.substring(19);
                                   //fixName(firstPart);
                                   pw.println(firstPart);
                             
                              } 
                         
                         }
              i got it. thanks guys.
              1 2 Previous Next