public String getUserAgreement() {
StringBuffer sb = null;
try {
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("userAgreement.txt");
InputStreamReader inputStreamReader = new InputStreamReader(inputStream,"UTF-8");
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
sb= new StringBuffer();
String text = null;
while ((text = bufferedReader.readLine()) != null) {
sb.append(text+"\n");
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return sb.toString();
}
this.getClass().getClassLoader().getResourceAsStream()可用
this.getClass().getClassLoader().getResource().getPath()部署到linux上有问题,需根据具体情况调试
|