38 lines
864 B
Java
38 lines
864 B
Java
package com.ruoyi.util;
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
|
|
/**
|
|
* 文件读取类
|
|
*/
|
|
public class FileUtil {
|
|
|
|
|
|
/**
|
|
* 获取文件内容
|
|
* @param fileName
|
|
* @return
|
|
*/
|
|
public static String readToStr(String fileName){
|
|
InputStream is = FileUtil.class.getClassLoader().getResourceAsStream(fileName);
|
|
ByteArrayOutputStream os = new ByteArrayOutputStream(2048);
|
|
byte[] buffer = new byte[1024];
|
|
|
|
String str;
|
|
try {
|
|
int length;
|
|
while((length = is.read(buffer)) != -1) {
|
|
os.write(buffer, 0, length);
|
|
}
|
|
|
|
str = os.toString("UTF-8");
|
|
} catch (IOException var5) {
|
|
throw new IllegalArgumentException("无效的密钥", var5);
|
|
}
|
|
return str;
|
|
}
|
|
|
|
}
|