首页 > 代码库 > java 读取文件转换成字符串
java 读取文件转换成字符串
public String readFromFile(File src) {
try {
BufferedReader bufferedReader = new BufferedReader(new FileReader(
src));
StringBuilder stringBuilder = new StringBuilder();
String content;
while((content = bufferedReader.readLine() )!=null){
stringBuilder.append(content);
}
return stringBuilder.toString();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
java 读取文件转换成字符串