/**
* 从本地CSV文件获得目标日期
* @param url
* @param orderIndex
* @return
*/
public static String getDateFromLocalCSV(String url , int orderIndex) {
//缓存读取流
BufferedReader csvReader = null;
try {
csvReader = new BufferedReader(new FileReader(url));
//当前行初始化
String line = null;
//当前索引
int index = 0;
while ((line=csvReader.readLine()) != null){
String [] item = line.split(",");
if (index == orderIndex && index != 0){
String orderStr = item[1];
return orderStr;
}
index++;
}
return null;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
csvReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
public static void main(String[] args) {
String url = "/home/lidengyin/Downloads/code/soft-cup/4565.csv";
String orderStr = getDateFromLocalCSV(url, 5);
System.out.println("orderStr: "+orderStr);
}