I'm writing a program which reads a lot of data files and finds special points in them. For that, I'm using the Scanner, which can parse the data (Which looks like that:)
-0.46368701 0.02136296
-0.46304701 0.03045747
-0.46240701 0.03045747
The first double goes to one array and the second to another.
For the question: the program is too slow. Can I use bufferedReader well in this case? I don't know if parsing it's argument will make the program insufficient.
Thank you!
BTW - the main methods of the program look like that:
private void init() throws IOException{
try {
scan = new Scanner(file);
} catch (FileNotFoundException e) {
System.out.println(e.toString());
e.printStackTrace();
}
lines = countLines(file);
value = new double[lines];
time = new double[lines];
vMinValue = new Vector<Double>();
vMinTime = new Vector<Double>();
}
//fill in time[] and value[] arrays
private void readFile(){
count=0;
System.out.println("Reading file...\n");
//Get to the start of the info -=CORE=-
while(scan.hasNext()){
if(scan.next().equals("(V)")){
System.out.println("Reading only 'Channel A' Values \n ");
break;
}
}
while(scan.hasNext()){
time[count] = scan.nextDouble();
value[count] = scan.nextDouble();
count++;
if(value[count]==Double.NEGATIVE_INFINITY) count--;
}
scan.close();
System.out.println("Input File Has Been Closed \n");
}
private void addMins(double[] a,int range){
for(int i=0;i<a.length;i++){
if( isMin(i,range)){
if((vMinValue.isEmpty() || vMinValue.get(vMinValue.size()-1)!=a[i])){ // provides only one minimum point
vMinValue.add((Double)value[i]);
vMinTime.add((Double)time[i]);
managMin.add(value[i]);
}
}
}
private boolean isMin(int i,int range){
boolean result = true;
for(int j=-range;j<=range;j++){
if(j==0) continue;
if(i+j<0 || i+j>value.length-1) continue;
if(value[i]>value[i+j]) return false;
}
return result;
}