@Log4j2
public class FileUtil {
/**
* 读取文件内容输出str
* @param file file
* @return String
*/
public static String convertFile(MultipartFile file){
try {
FileInputStream fis = (FileInputStream) file.getInputStream();
byte[] buffer = new byte[100];
StringBuilder sb = new StringBuilder();
while (fis.read(buffer) != -1) {
sb.append(new String(buffer));
buffer = new byte[100];
}
fis.close();
//可能存在文件转str后,出现部分定义NUL的数据 故进行转义
return sb.toString().replaceAll("\\\00","");
}catch (Exception ex){
log.error(ex.getMessage(),ex);
}
return null;
}
/**
* 基础校