使用 GWTUpload 将 CSV 文件上传到 GAE 后,我在解析 CSV 文件时遇到问题。上传似乎工作正常,但我在使用getInputStream
FileItem 的方法从文件中读取数据时遇到问题。我的代码如下所示:
for (FileItem item : sessionFiles) {
if (!item.isFormField()) {
logger.log(Level.INFO, "file item is: " + item.getName());
try{
/* The below line prints -1 when uncommented
* logger.log(Level.INFO, "input stream read is: " + item.getInputStream().read());
*/
InputStreamReader insr = new InputStreamReader(item.getInputStream());
//This is just for debugging purposes
//String insString = Integer.toString(insr.read());
BufferedReader br = new BufferedReader(insr);
//logger.log(Level.INFO, "first row is: " + br.readLine());
logger.log(Level.INFO, "calling on parseCSV");
parseCSV(br);
}
catch(Exception e){
throw new UploadActionException(e);
}
}
}
我只使用 SingleUploader 上传单个文件,它似乎已正确上传。例如,
logger.log(Level.INFO, "file item is: " + item.getName());
行正确输出 CSVExample.csv。然而
logger.log(Level.INFO, "file item is: " + item.getName());
行总是输出-1,表示流的结束。
我的 csv 文件如下所示:
,vendor_food,open,emptyKey,,Hot Dogs,49.28241993,-123.1243637
DT56,vendor_food,open,invalidLat,Coal Harbour Seawall - 200 Metres Northeast of Broughton St,Hot Dogs,tt,-123.1236823
E423,vendor_food,open,invalidLon,,Hot Dogs,49.28449252,tt
EB05,vendor_food,open,emptyLat,,Hot Dogs,,-123.1432294
EB07,vendor_food,open,emptyType,,,49.28763934,-123.1425256
GM02,vendor_food,pending,closed,,Hot Dogs,49.28298256,-123.1172526
GM05,vendor_food,open,valid,sadsadsadsadsadsad,Hot Dogs,49.28051786,-123.1209519
有人对我做错了什么有任何建议吗?