虽说很简单,但是刚开始思想走了点弯路,贴出来 以记之;
public static List<String> getData(String readPath) throws IOException {
File file = new File(readPath);
if (!file.exists()) {
System.out.println("File not exist!");
System.exit(0);
}
BufferedReader br;
br = new BufferedReader(new FileReader(readPath));
String line;
String[] strArr = null;
List<String> list = new ArrayList<String>();
Pattern p = Pattern.compile("^\\s*\\d.*");
if (file.exists()) {
int n = 1;
while ((line = br.readLine()) != null) {
n++;
if (p.matcher(line).matches()) {
strArr = line.replace(";","").trim().split(",");// 把最后一个分号去掉(可能还有很多方法),然后根据与文件中的分隔符得到单个数据
for (String data : strArr) {
data.trim();
list.add(data);
}
}
}
}
br.close();
return list;
}