我正在编写一个程序,它读取大量数据文件并在其中找到特殊点。 对于这一点,我使用的扫描仪,它可以分析数据(这看起来像:)BufferedReader或扫描仪? (Java)
-0.46368701 0.02136296
-0.46304701 0.03045747
-0.46240701 0.03045747
第一双去一个阵列和第二到另一个。
对于这个问题:程序太慢了。在这种情况下,我可以很好地使用bufferedReader吗?我不知道解析它的参数是否会导致程序不足。
谢谢!
BTW - 该方案的主要方法看起来像:
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;
}
什么是你的代码是什么样子? – Kayaman
我通常使用BufferedReader。但认为可能还有其他原因。只有这么多的信息才能导致解决方案。你是否为单个值创建单独的数组? – Kartic
显示你的代码会很好。 – JonasCz