第1个回答 2013-08-31
System.out.println("上传文件中……");
FormFile file = billForm.getFile();//取得上传的文件
if (file != null && file.getFileSize() == 0) {// 判断上传数据是否为空
request.setAttribute("msg", "该文件无内容或为空");
InputStream read = file.getInputStream();
String[] sp = null;
int i=0;
BufferedReader reader = new BufferedReader(new InputStreamReader(read));//直接对数据流进行操作/****以下为读取数据并赋值**/
String line;
line = reader.readLine();
CsPosCommercial cp = null;
while (line != null) {
i++;
cp= new CsPosCommercial();
System.out.println(line);
sp = line.split("\\|");
cp.setWtCommerLikename(sp[0]);
cp.getId().setWtCommerMercode(sp[1]);
cp.getId().setWtCommerTrmcode(sp[2]);
cp.setWtAcquirer(sp[3]);
cp.setWtBusTag(Long.valueOf(sp[5]));
cp.setWtState("01");
cp.setWtMnKey(sp[4]);
line = reader.readLine(); // 读取下一行
}
request.setAttribute("msg", "数据导入成功!");
read.close();//关闭数据流
} 自己研究吧