main
黄海 9 months ago
parent 6e9af88db6
commit cb90fd415a

@ -51,26 +51,9 @@ public class CommonUtil {
* @return * @return
* @throws IOException * @throws IOException
*/ */
public static String txt2String(String path) throws IOException { public static String txt2String(String path) {
InputStream is = CommonUtil.class.getClassLoader().getResourceAsStream(path); InputStream is = CommonUtil.class.getClassLoader().getResourceAsStream(path);
BufferedInputStream bis = null; return IoUtil.read(is, "UTF-8");
StringBuilder sb = new StringBuilder();
try {
bis = new BufferedInputStream(is);
byte[] temp = new byte[1024];
int len;
while ((len = bis.read(temp)) != -1) {
sb.append(new String(temp, 0, len, StandardCharsets.UTF_8));
}
} finally {
if (bis != null) {
bis.close();
}
if (is != null) {
is.close();
}
}
return sb.toString();
} }
/** /**

@ -41,26 +41,9 @@ public class CommonUtil {
* @return * @return
* @throws IOException * @throws IOException
*/ */
public static String txt2String(String path) throws IOException { public static String txt2String(String path) {
InputStream is = CommonUtil.class.getClassLoader().getResourceAsStream(path); InputStream is = CommonUtil.class.getClassLoader().getResourceAsStream(path);
BufferedInputStream bis = null; return IoUtil.read(is, "UTF-8");
StringBuilder sb = new StringBuilder();
try {
bis = new BufferedInputStream(is);
byte[] temp = new byte[1024];
int len;
while ((len = bis.read(temp)) != -1) {
sb.append(new String(temp, 0, len, StandardCharsets.UTF_8));
}
} finally {
if (bis != null) {
bis.close();
}
if (is != null) {
is.close();
}
}
return sb.toString();
} }
/** /**

@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.jfinal.kit.PathKit; import com.jfinal.kit.PathKit;
import com.jfinal.kit.StrKit; import com.jfinal.kit.StrKit;
import cn.hutool.core.io.IoUtil;
import com.jfinal.plugin.activerecord.Page; import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record; import com.jfinal.plugin.activerecord.Record;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
@ -48,26 +49,9 @@ public class CommonUtil {
* @return * @return
* @throws IOException * @throws IOException
*/ */
public static String txt2String(String path) throws IOException { public static String txt2String(String path) {
InputStream is = CommonUtil.class.getClassLoader().getResourceAsStream(path); InputStream is = CommonUtil.class.getClassLoader().getResourceAsStream(path);
BufferedInputStream bis = null; return IoUtil.read(is, "UTF-8");
StringBuilder sb = new StringBuilder();
try {
bis = new BufferedInputStream(is);
byte[] temp = new byte[1024];
int len;
while ((len = bis.read(temp)) != -1) {
sb.append(new String(temp, 0, len, StandardCharsets.UTF_8));
}
} finally {
if (bis != null) {
bis.close();
}
if (is != null) {
is.close();
}
}
return sb.toString();
} }
/** /**

Loading…
Cancel
Save