problem in FileWriter

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shana07
    Contributor
    • Jan 2007
    • 280

    #46
    Originally posted by r035198x
    You can put println statements to see how far it went and where it stopped.
    From the result text file (as it keep hang - So I stopped it) it shows that I have looping problem.

    What happened was, for each for looping it keeps compare with Entry # 1 and 1000 lines of output file. Then loop again for second arraylist Entry # 2 & compare with 1000 lines of output file......
    As I have arraylist size about 800 and lines of output file about 1000.

    It's supposed to compare current arraylist entry let's assume Entry # 1 with output line # 1 and exit the looping, then repeate again Entry # 2 with output line # 2 and on....

    How am I supposed to do about my looping codes....?
    Code:
    Entry # 1 with output line # 1 - compare - exit looping.
    Entry # 2 with output line # 2- compare - exit looping...
    ........
    ... at least it stops when there is no more entry in ArrayList eventho there are few lines in output file..
    Kindly please check below my current looping....
    Code:
    while ((line = input.readLine()) != null ) // I guess here is the problem
                {
                    for (int i = 0; i <myArrayList.size(); i++)  // and this part too.
                  {
                     // line = input.readLine();
                    String[] theline = line.split(" ");
                    String sdata = theline[0];
                    String snumber = theline[1];
                    String svalue = theline[2];

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #47
      Originally posted by shana07
      From the result text file (as it keep hang - So I stopped it) it shows that I have looping problem.

      What happened was, for each for looping it keeps compare with Entry # 1 and 1000 lines of output file. Then loop again for second arraylist Entry # 2 & compare with 1000 lines of output file......
      As I have arraylist size about 800 and lines of output file about 1000.

      It's supposed to compare current arraylist entry let's assume Entry # 1 with output line # 1 and exit the looping, then repeate again Entry # 2 with output line # 2 and on....

      How am I supposed to do about my looping codes....?
      Code:
      Entry # 1 with output line # 1 - compare - exit looping.
      Entry # 2 with output line # 2- compare - exit looping...
      ........
      ... at least it stops when there is no more entry in ArrayList eventho there are few lines in output file..
      Kindly please check below my current looping....
      Code:
      while ((line = input.readLine()) != null ) // I guess here is the problem
      {
      for (int i = 0; i <myArrayList.size(); i++) // and this part too.
      {
      // line = input.readLine();
      String[] theline = line.split(" ");
      String sdata = theline[0];
      String snumber = theline[1];
      String svalue = theline[2];

      Well then you don't need a for-loop for reading the arraylist data. Your design should look something like
      Code:
       int index = 0; 
      while ((line = input.readLine()) != null )			{
      		Entry e = myArrayList.get(index++);
      		 ....

      Comment

      • shana07
        Contributor
        • Jan 2007
        • 280

        #48
        Originally posted by r035198x
        Well then you don't need a for-loop for reading the arraylist data. Your design should look something like
        Code:
         int index = 0; 
        while ((line = input.readLine()) != null )			{
        		Entry e = myArrayList.get(index++);
        		 ....
        Erm I have tried that, it's still keep reading the next lines when finish compare with entry # 1.
        Is there any way to comment the while loop for reading next line?
        But then it's going to have another problem - compare with only line # 1.
        How to make it read to the next line without only that syntax....
        phew...!

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #49
          Originally posted by shana07
          Erm I have tried that, it's still keep reading the next lines when finish compare with entry # 1.
          Is there any way to comment the while loop for reading next line?
          But then it's going to have another problem - compare with only line # 1.
          How to make it read to the next line without only that syntax....
          phew...!
          I thought you wanted it to read the next line when it finishes comparing with line # 1.
          Also if you have written to the file the values of Entries(not Entry objects themselves) then you need to call readLine again inside the while loop.

          Comment

          Working...