Need java help on reading intger elements from file to array list

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nomad
    Recognized Expert Contributor
    • Mar 2007
    • 664

    #16
    Originally posted by prometheuzz
    You can or can't use the Scanner class?

    Anyway, Scanner examples can be found in the tutorial I posted, and here's an example of how to do it without the Scanner class:
    [CODE=java]import java.io.*;

    public class Main {
    public static void main(String[] args) throws IOException {
    BufferedReader buffer =
    new BufferedReader( new FileReader("Mai n.java"));
    String lineOfText;
    while((lineOfTe xt = buffer.readLine ()) != null) {
    System.out.prin tln("> "+lineOfTex t);
    }
    buffer.close();
    }
    }[/CODE]
    Have a look at the java.lang.Integ er class how to parse a String to a numerical value.

    Good luck.
    clue read() method
    nomad

    Comment

    • needhelp123
      New Member
      • May 2007
      • 21

      #17
      Originally posted by nomad
      clue read() method
      nomad

      s by using parseint

      even i kno this concept but but what i need is.... how you will put this into an array

      Comment

      • prometheuzz
        Recognized Expert New Member
        • Apr 2007
        • 197

        #18
        Originally posted by nomad
        clue read() method
        nomad
        I would't do that: read() only return single characters. How will you read a numerical value which is larger than 9?

        Comment

        • prometheuzz
          Recognized Expert New Member
          • Apr 2007
          • 197

          #19
          Originally posted by needhelp123
          s by using parseint
          ...
          Yes, that is correct.


          Originally posted by needhelp123
          ...
          even i kno this concept but but what i need is.... how you will put this into an array
          You needed to use an ArrayList and not an array, right?
          Well then, create an instance of an ArrayList and use it's add methof to add Integers to it. That's all there is to it!
          ; )

          Comment

          • nomad
            Recognized Expert Contributor
            • Mar 2007
            • 664

            #20
            Originally posted by prometheuzz
            I would't do that: read() only return single characters. How will you read a numerical value which is larger than 9?
            so this would not work
            This folowing statement use a while loo to read the data file in a FileInputStream object. called largerfile:

            int newByte = 0;
            while (newByte != -1) {
            newByte =largerfile.rea d();
            System.out.prin t(newByte + " ");
            }

            nomad

            Comment

            • needhelp123
              New Member
              • May 2007
              • 21

              #21
              Originally posted by prometheuzz
              Yes, that is correct.




              You needed to use an ArrayList and not an array, right?
              Well then, create an instance of an ArrayList and use it's add methof to add Integers to it. That's all there is to it!
              ; )
              can u please give example for this....

              Comment

              • JosAH
                Recognized Expert MVP
                • Mar 2007
                • 11453

                #22
                Originally posted by nomad
                so this would not work
                This folowing statement use a while loo to read the data file in a FileInputStream object. called largerfile:

                int newByte = 0;
                while (newByte != -1) {
                newByte =largerfile.rea d();
                System.out.prin t(newByte + " ");
                }

                nomad
                No insult intended but you'd better leave this thread to Prometheuzz; he can
                handle this fine. He doesn't need your or my intervening remarks here. If you
                want to know anything about stream IO feel free to start your own thread about
                it and I'll read (and possibly answer) your question too. Prometheuzz is right
                on target with this thread; read all about it and feel free to post corrections.

                kind regards,

                Jos

                Comment

                • needhelp123
                  New Member
                  • May 2007
                  • 21

                  #23
                  Originally posted by needhelp123
                  can u please give example for this....

                  can you plese give exAMPLE FOR THIS PRO

                  Comment

                  • prometheuzz
                    Recognized Expert New Member
                    • Apr 2007
                    • 197

                    #24
                    Originally posted by needhelp123
                    can you plese give exAMPLE FOR THIS PRO
                    Like I said: I don't know exactly what it is you need help with, and begging for code isn't helping you either.

                    You had better show me (or us) that you put some effort and research in what I have suggested to you because I pretty much told you what to do in order to finish this assignment.

                    If there is something not clear to you, then you need to be specific and tell me (us) what it is you don't understand.


                    Edit: I'll check up on this thread tomorrow morning because it's way passed my bed time (says my girlfriend).

                    Comment

                    • needhelp123
                      New Member
                      • May 2007
                      • 21

                      #25
                      Originally posted by prometheuzz
                      Like I said: I don't know exactly what it is you need help with, and begging for code isn't helping you either.

                      You had better show me (or us) that you put some effort and research in what I have suggested to you because I pretty much told you what to do in order to finish this assignment.

                      If there is something not clear to you, then you need to be specific and tell me (us) what it is you don't understand.


                      Edit: I'll check up on this thread tomorrow morning because it's way passed my bed time (says my girlfriend).
                      ok dude...
                      i need help that
                      i need a coding help to transfer those data to array element....

                      Comment

                      • r035198x
                        MVP
                        • Sep 2006
                        • 13225

                        #26
                        Originally posted by needhelp123
                        ok dude...
                        i need help that
                        i need a coding help to transfer those data to array element....
                        Follow the advice that has been given already. If you get stuck with it, no problem. Just post the code that you will have written and see what happens.

                        Comment

                        • needhelp123
                          New Member
                          • May 2007
                          • 21

                          #27
                          Originally posted by r035198x
                          Follow the advice that has been given already. If you get stuck with it, no problem. Just post the code that you will have written and see what happens.
                          [/QUOTE]


                          thank you people helping in that mean procedure,,,,,, ,,,,,,
                          i got a code

                          Comment

                          • prometheuzz
                            Recognized Expert New Member
                            • Apr 2007
                            • 197

                            #28
                            Originally posted by needhelp123
                            thank you people helping in that mean procedure,,,,,, ,,,,,,
                            i got a code
                            What are you tryinh to say with: mean procedure? Do you feel you are treated badly?
                            And what do you mean by: i got a code?

                            Comment

                            • JosAH
                              Recognized Expert MVP
                              • Mar 2007
                              • 11453

                              #29
                              Originally posted by prometheuzz
                              What are you tryinh to say with: mean procedure? Do you feel you are treated badly?
                              And what do you mean by: i got a code?
                              My guess is that the OP managed to scrape a non-understood snippet of code
                              from the internet somewhere which (sort of) compiles and (sort of) seems to do
                              what the OP wants it to do. Programming is a mean business indeed ;-)

                              Confused? Watch out for the next episode for "Teh WAnTeD CodeZ!!!eleven1 1!"

                              kind regards,

                              Jos

                              Comment

                              • needhelp123
                                New Member
                                • May 2007
                                • 21

                                #30
                                Originally posted by prometheuzz
                                What are you tryinh to say with: mean procedure? Do you feel you are treated badly?
                                And what do you mean by: i got a code?

                                no i am not...

                                just i said u that.. i have worked on that... and i got that concept....

                                of data transfer from file to array list..

                                using bufferreader, and bufferwriter... for input and out put...

                                using fileinput stream...
                                thank you prom.. for helping me in this

                                Comment

                                Working...