因为在tomcat的环境下默认的路径会在tomcat的bin文件夹中,因此需要将路径索引到.class的文件夹
String src = new String(this.getClass().getClassLoader().getResource("/").getPath()+"文件名");
获取输入流
File file = new File(src);
InputStreamReader isr = new InputStreamReader(new FileInputStream(file),"UTF-8");
因为默认的是UNICODE,需要指定用UTF-8编码读取,否则会乱码。
//按行读取
reader = new BufferedReader(isr);
String tempString = null;
while ((tempString = reader.readLine()) != null) {
sList.add(tempString);
}