![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Nov 2004
Posts: 84
Rep Power: 4
![]() |
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 |
|
|
|
|
|
#2 |
|
Expert Programmer
|
Are you kidding? Windows loves NULL strings and NULL data pointers
It seems to use them a lot as it is.
__________________
Clifford Matthew Roche <geek@cliffordroche.com> Web Hosting: http://www.crd-hosting.com Consulting: http://www.crdev-consulting.com |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Nov 2004
Posts: 84
Rep Power: 4
![]() |
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|