private static final Logger log = LoggerFactory.getLogger(FindEmployeeService.class); public String execute(HttpServletRequest req, HttpServletResponse res) {
String fileName = req.getParameter("fileName");
String path = req.getSession().getServletContext().getRealPath("txt") +"\\"+ fileName +".txt";
List<String> strList = new ArrayList<String>();
try {
strList = getFileContent(path);
System.out.println(strList.size());
} catch (FileNotFoundException e) {
log.info("BatchAddEmployeeService36:异常");
log.error("BatchAddEmployeeService37:异常");
e.printStackTrace();
}
return "right/batchAddSuccess.jsp";
} /**
* 将文本读取到List中返回
* */
public List<String> getFileContent(String path) throws FileNotFoundException {
List<String> strList = new ArrayList<String>();
InputStreamReader read = null;
BufferedReader reader = null;
try {
File file = new File(path);
read = new InputStreamReader(new FileInputStream(file), "UTF-8");
reader = new BufferedReader(read);
String line;
while ((line = reader.readLine()) != null) {
strList.add(line);
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (read != null) {
try {
read.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return strList;
}
已经写到这了,自己会写还会贴出来问吗?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货