mirror of
https://github.com/201206030/novel-plus.git
synced 2025-06-24 04:46:37 +00:00
增加小说内容TXT文本存储方案(一行配置切换)
This commit is contained in:
@ -19,6 +19,7 @@ import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 文件操作工具类
|
||||
*
|
||||
* @author 11797
|
||||
*/
|
||||
@UtilityClass
|
||||
@ -27,8 +28,8 @@ public class FileUtil {
|
||||
|
||||
/**
|
||||
* 网络图片转本地
|
||||
* */
|
||||
public String network2Local(String picSrc,String picSavePath,String visitPrefix) {
|
||||
*/
|
||||
public String network2Local(String picSrc, String picSavePath, String visitPrefix) {
|
||||
InputStream input = null;
|
||||
OutputStream out = null;
|
||||
try {
|
||||
@ -53,45 +54,41 @@ public class FileUtil {
|
||||
}
|
||||
|
||||
out.flush();
|
||||
if( ImageIO.read(picFile) == null){
|
||||
if (ImageIO.read(picFile) == null) {
|
||||
picSrc = "/images/default.gif";
|
||||
}
|
||||
|
||||
}catch (Exception e){
|
||||
log.error(e.getMessage(),e);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
|
||||
picSrc = "/images/default.gif";
|
||||
}finally {
|
||||
if(input != null){
|
||||
try {
|
||||
input.close();
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage(),e);
|
||||
}finally {
|
||||
if(out != null){
|
||||
try {
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage(),e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
closeStream(input, out);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return picSrc;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private void closeStream(InputStream input, OutputStream out) {
|
||||
if (input != null) {
|
||||
input.close();
|
||||
}
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断文件是否为图片
|
||||
*
|
||||
* @param file 需要判断的文件
|
||||
* @return true:是图片,false:不是图片
|
||||
* */
|
||||
*/
|
||||
@SneakyThrows
|
||||
public boolean isImage(File file){
|
||||
public boolean isImage(File file) {
|
||||
|
||||
BufferedImage bi = ImageIO.read(file);
|
||||
|
||||
@ -100,6 +97,27 @@ public class FileUtil {
|
||||
|
||||
}
|
||||
|
||||
public void writeContentToFile(String fileSavePath, String fileSrc, String content) {
|
||||
OutputStream out = null;
|
||||
try {
|
||||
File file = new File(fileSavePath + fileSrc);
|
||||
File parentFile = file.getParentFile();
|
||||
if (!parentFile.exists()) {
|
||||
parentFile.mkdirs();
|
||||
}
|
||||
out = new FileOutputStream(file);
|
||||
out.write(content.getBytes());
|
||||
byte[] b = new byte[4096];
|
||||
out.flush();
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
throw new RuntimeException("文件写入失败");
|
||||
} finally {
|
||||
closeStream(null, out);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -71,3 +71,7 @@ sharding:
|
||||
|
||||
|
||||
|
||||
txt:
|
||||
save:
|
||||
storage: db #存储介质,db:数据库,file:txt文本
|
||||
path: /Users/xiongxiaoyang/books #txt小说文本保存路径
|
@ -74,7 +74,10 @@ logging:
|
||||
|
||||
|
||||
|
||||
|
||||
txt:
|
||||
save:
|
||||
storage: db #存储介质,db:数据库,file:txt文本
|
||||
path: /Users/xiongxiaoyang/books #txt小说文本保存路径
|
||||
|
||||
|
||||
|
||||
|
@ -44,7 +44,7 @@
|
||||
</javaClientGenerator>
|
||||
|
||||
<!--生成全部表tableName设为%-->
|
||||
<table tableName="news"/>
|
||||
<table tableName="book_index"/>
|
||||
|
||||
<!-- 指定数据库表 -->
|
||||
<!--<table schema="jly" tableName="job_position" domainObjectName="JobPositionTest"/>-->
|
||||
|
Reference in New Issue
Block a user