快速 CSV 解析Apache Commons CSV使用注意事项split opencsv
我有一个Java服务器应用程序,可以下载CSV文件并对其进行解析。解析可能需要 5 到 45 分钟,每小时进行一次。此方法是应用的瓶颈,因此不会过早优化。到目前为止的代码:
client.executeMethod(method);
InputStream in = method.getResponseBodyAsStream(); // this is http stream
String line;
String[] record;
reader = new BufferedReader(new InputStreamReader(in), 65536);
try {
// read the header line
line = reader.readLine();
// some code
while ((line = reader.readLine()) != null) {
// more code
line = line.replaceAll("\"\"", "\"NULL\"");
// Now remove all of the quotes
line = line.replaceAll("\"", "");
if (!line.startsWith("ERROR"){
//bla bla
continue;
}
record = line.split(",");
//more error handling
// build the object and put it in HashMap
}
//exceptions handling, closing connection and reader
是否有任何现有的库可以帮助我加快速度?我可以改进现有代码吗?