41 lines
1.4 KiB
Java
41 lines
1.4 KiB
Java
import java.io.*;
|
|
import java.util.ArrayList;
|
|
|
|
public class DataFileReader {
|
|
static ArrayList<ArrayList<Double>> readFile(String file){
|
|
ArrayList<ArrayList<Double>> data = new ArrayList<ArrayList<Double>>();
|
|
//Count: leere Zeilen werden nicht mitverwendet
|
|
int count = 0;
|
|
try(BufferedReader stream = new BufferedReader(new FileReader(file))){
|
|
while(true){
|
|
String line = stream.readLine();
|
|
if(line == null){
|
|
break;
|
|
}
|
|
if(!line.contains("#")){
|
|
String[] parts = line.split("[ |\t]");
|
|
data.add(new ArrayList<Double>());
|
|
for(String s : parts){
|
|
try{
|
|
data.get(count).add(Double.parseDouble(s));
|
|
}catch(NumberFormatException e){
|
|
}
|
|
}
|
|
if(data.get(count).size() == 0){
|
|
data.remove(count);
|
|
}else{
|
|
count++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch(FileNotFoundException e){
|
|
e.printStackTrace();
|
|
System.out.println("file " + file + " not found");
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
return data;
|
|
}
|
|
}
|