🌺前言
java文件内容转换为字符串
java
public class FileToStringUtils {
public static String convertMultipartFileToString(MultipartFile file) throws IOException {
if (file == null || file.isEmpty()) {
throw new IllegalArgumentException("File cannot be null or empty");
}
try (BufferedReader reader = new BufferedReader(new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8))) {
StringBuilder stringBuilder = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
stringBuilder.append(line);
stringBuilder.append("\n");
}
return stringBuilder.toString();
}
}
}
文章最后更新于 2024-11-30 17:15:16
作者:徐徐版权声明:转载请注明文章出处
留言

~~空空如也