Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 6th, 2004, 9:18 PM   #1
groovicus
Programmer
 
Join Date: Nov 2004
Posts: 84
Rep Power: 4 groovicus is on a distinguished road
I have a small method that reads a text file into an arraylist. I know that after each line, there is a blank, which I don't want to add to the array. I also know that if I hit 3 null lines in a row, that I am at the end of the file. For some reason, this is not working at all.

Sometimes I need to just ask the question out loud to figure out my mistake, so here goes..what the blazes am I missing..it has to be something so simple, and I am just too tired to see it.

 public ArrayList processList(File f){
    this.f =f;
    
    if(f.canRead()) System.out.println("F is " + f );   //error check
    
    try{
      br = new BufferedReader(new FileReader(f));
    }catch(Exception t){
      System.out.println("file is not readable");
    }
    
    int count =0;  
    while(count<3){
      
      try{       
        temp = br.readLine(); 
        if(temp==null) count++;
        pst.add(temp); count = 0;
      }catch(Exception x){
        System.out.println("Something is wrong");
      }
    }
    return pst;
  }

I realize it is ugly, I'll clean it up later...all I am getting for output is exception catches.... <_<

EDIT: Ok, figured it out. If the file is null to begin with, it will obviously bomb.. D'OH! :blink:
__________________
HijackThis Team-SFDC
groovicus is offline   Reply With Quote
Old Dec 7th, 2004, 1:23 AM   #2
kurifu
Expert Programmer
 
kurifu's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia (Canada)
Posts: 784
Rep Power: 5 kurifu is on a distinguished road
Send a message via ICQ to kurifu Send a message via MSN to kurifu
Are you kidding? Windows loves NULL strings and NULL data pointers It seems to use them a lot as it is.
__________________
Clifford Matthew Roche &lt;geek@cliffordroche.com&gt;
Web Hosting: http://www.crd-hosting.com
Consulting: http://www.crdev-consulting.com
kurifu is offline   Reply With Quote
Old Dec 7th, 2004, 7:18 PM   #3
groovicus
Programmer
 
Join Date: Nov 2004
Posts: 84
Rep Power: 4 groovicus is on a distinguished road
Just to add to the stupidity...I changed my code so it would read the file like I wanted, so now I have an entirely new issue :wacko:

 public ArrayList processList(File f) throws IOException{
    
    RandomAccessFile raf = new RandomAccessFile(f, "r");
 
    String temp = null;
    try {
      while((temp = raf.readLine( )) != null) 
      System.out.println(temp);
      pst.add(temp);
      System.out.println("size of pst is " + pst.size() );
    }catch(IOException e) {
      System.out.println(e + " reading lines.");
    }
     raf.close( ); 
     Return pst;

}

It is reading the strings fine, but when I check the size of pst, it doesn't do anything... not even an error.. Anybody have a nice link that I could use to pry my head from my posterior?? Is it skipping because it is returning a null value? I am soooo confused. <_<

EDIT: pst is declared as a global ArrayList
__________________
HijackThis Team-SFDC
groovicus is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:19 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC