很久没用都忘记了,记录一下:
public static String readFileContent(String fileName) {
File file = new File(fileName);
BufferedReader reader = null;
StringBuilder builder = new StringBuilder();
try {
reader = new BufferedReader(new FileReader(file));
String tempStr;
while ((tempStr = reader.readLine()) != null) {
builder.append(tempStr);
}
reader.close();
return builder.toString();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
return builder.toString();
}