Okay, so I have a java program I'm working on, and I want to import the contents of a file into a custom linkedList. The code worked fine until I added a loop which had the code running through every file in the directory and its subdirectories (which should just be added to the linkedList). However, the code fails in a loop where it should actually go through fine, since it did so before.
code:
Example file:PHP Code:
public static RecordsLinkedList ReadInFromFile() throws IOException, FileNotFoundException{
//initialize variables required for reading in
String[] fResult={""};
String projectName, projectID, date, description, client2;
double rate, time;
RecordsLinkedList returnValues=new RecordsLinkedList();
//re-create the path to the file by making a File array of all files and subdirectories within the /Records folder
String temp3=recurseInDirFrom(home+"/Records");
String[] paths=temp3.split(",");
File[] path=new File[paths.length];
for(int z=0; z<paths.length;z++){
path[z]=new File(paths[z].toString());
}
//run through the loop for all files contained within the /Records directory, if it's a directory do nothing
for(int b=0; b<path.length; b++){
if(!path[b].isDirectory()){
//set up input tools
FileReader fr=new FileReader(path[b]);
BufferedReader input=new BufferedReader(fr);
StringBuilder content=new StringBuilder();
//initiate variables for result
String line=null;
String[] result;
try{
while((line=input.readLine())!=null){
content.append(line);
content.append(System.getProperty("line.seperator"));
}
}
finally{
input.close();
}
//split the contents of the file into sections
result=content.toString().split("null");
//set up the array and put each individual entry into a new position
String[] result3=new String[result.length/4];
int ind=0;
System.out.println(result.length/4);
for(int g=0; g<result.length+3;g+=4){
if(ind!=(result.length/4)){
System.out.println(ind+","+g);
result3[ind]=result[g]+"\n"+result[g+1]+"\n"+result[g+2]+"\n"+result[g+3]; //error lies here, it only runs through this loop once!
System.out.println("Result: "+result3[ind]);
ind++;
}
else{
continue;
}
//Remove duplicate entries from the array
Set set = new HashSet(Arrays.asList(result3));
fResult = (String[])(set.toArray(new String[set.size()]));
for(int t=0; t<fResult.length; t++){
System.out.println("--------------------------");
System.out.println(fResult[t]);
System.out.println("--------------------------");
if(fResult[t]==null){
fResult[t]="";
}
}
for(int y=0; y<fResult.length; y++){
System.out.println(fResult.length);
String temp=fResult[y];
System.out.println("--------------------------");
System.out.println(temp);
System.out.println("--------------------------");
temp.replaceAll("null", "");
System.out.println("--------------------------");
System.out.println(temp);
System.out.println("--------------------------");
String[] tempArray=temp.split(":");
System.out.println("--------------------------");
System.out.println(tempArray.length);
System.out.println("--------------------------");
projectName=tempArray[1];
projectID=tempArray[3];
date=tempArray[5];
description=tempArray[7];
rate=Double.parseDouble(tempArray[9]);
time=Double.parseDouble(tempArray[11]);
client2=tempArray[13];
Records temp2=new Records(projectName, projectID, rate, date, description, time, client2);
returnValues.add(temp2);
}
}
}
}
//return the final result LinkedList
return returnValues;
}
This is really frustrating, I can't help feeling I'm overlooking something simple Any help would be greatly appreciated!Project Name: John Childcare ProjectID: JOHN311
Date: 8/12/08 Description: John's Childcare Services
Rate: 225.5 Time Spent: 6.0
Client: John Doe
Project Name: John Childcare ProjectID: JOHN311
Date: 4/12/08 Description: John's Childcare Services
Rate: 220.5 Time Spent: 5.0
Client: John Doe
Project Name: John Childcare ProjectID: JOHN311
Date: 8/12/08 Description: John's Childcare Services
Rate: 225.5 Time Spent: 6.0
Client: John Doe
Project Name: John Childcare ProjectID: JOHN311
Date: 4/12/08 Description: John's Childcare Services
Rate: 220.5 Time Spent: 5.0
Client: John Doe
Project Name: John Childcare ProjectID: JOHN311
Date: 8/12/08 Description: John's Childcare Services
Rate: 225.5 Time Spent: 6.0
Client: John Doe
Project Name: John Childcare ProjectID: JOHN311
Date: 4/12/08 Description: John's Childcare Services
Rate: 220.5 Time Spent: 5.0
Client: John Doe
Thanks in advance,
Lswest
Bookmarks