public static String file2String(File file) throws IOException {
if (file.exists()) {
byte[] data = new byte[(int) file.length()];
boolean result;
FileInputStream inputStream = null;
try {
inputStream = new FileInputStream(file);
int len = inputStream.read(data);
result = len == data.length;
} finally {
if (inputStream != null) {
inputStream.close();
}
}
if (result) {
return new String(data);
}
}
return null;
}
将文件转换为字符串
最新推荐文章于 2023-07-04 10:59:35 发布