diff --git a/headless/core/src/main/java/com/tencent/supersonic/headless/core/file/FileHandlerImpl.java b/headless/core/src/main/java/com/tencent/supersonic/headless/core/file/FileHandlerImpl.java index c22573671..a25ce17fa 100644 --- a/headless/core/src/main/java/com/tencent/supersonic/headless/core/file/FileHandlerImpl.java +++ b/headless/core/src/main/java/com/tencent/supersonic/headless/core/file/FileHandlerImpl.java @@ -3,6 +3,8 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; + +import java.io.File; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -17,9 +19,9 @@ @Slf4j @Component public class FileHandlerImpl implements FileHandler { + public static final String FILE_SPILT = File.separator; private final LocalFileConfig localFileConfig; - public FileHandlerImpl(LocalFileConfig localFileConfig) { this.localFileConfig = localFileConfig; } @@ -31,8 +33,8 @@ public void backupFile(String fileName) { createDir(dictDirectoryBackup); } - String source = localFileConfig.getDictDirectoryLatest() + "/" + fileName; - String target = dictDirectoryBackup + "/" + fileName; + String source = localFileConfig.getDictDirectoryLatest() + FILE_SPILT + fileName; + String target = dictDirectoryBackup + FILE_SPILT + fileName; Path sourcePath = Paths.get(source); Path targetPath = Paths.get(target); try { @@ -88,7 +90,7 @@ public void writeFile(List lines, String fileName, Boolean append) { if (!existPath(dictDirectoryLatest)) { createDir(dictDirectoryLatest); } - String filePath = dictDirectoryLatest + "/" + fileName; + String filePath = dictDirectoryLatest + FILE_SPILT + fileName; if (existPath(filePath)) { backupFile(fileName); } @@ -117,7 +119,7 @@ public String getDictRootPath() { @Override public Boolean deleteDictFile(String fileName) { backupFile(fileName); - deleteFile(localFileConfig.getDictDirectoryLatest() + "/" + fileName); + deleteFile(localFileConfig.getDictDirectoryLatest() + FILE_SPILT + fileName); return true; } diff --git a/headless/core/src/main/java/com/tencent/supersonic/headless/core/file/LocalFileConfig.java b/headless/core/src/main/java/com/tencent/supersonic/headless/core/file/LocalFileConfig.java index 6e2c8b4ba..7dc232e3d 100644 --- a/headless/core/src/main/java/com/tencent/supersonic/headless/core/file/LocalFileConfig.java +++ b/headless/core/src/main/java/com/tencent/supersonic/headless/core/file/LocalFileConfig.java @@ -1,10 +1,13 @@ package com.tencent.supersonic.headless.core.file; +import com.tencent.supersonic.headless.core.knowledge.helper.HanlpHelper; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; +import java.io.FileNotFoundException; + @Data @Configuration @Slf4j @@ -18,16 +21,21 @@ public class LocalFileConfig { private String dictDirectoryBackup; public String getDictDirectoryLatest() { - return getResourceDir() + dictDirectoryLatest; + return getDictDirectoryPrefixDir() + dictDirectoryLatest; } public String getDictDirectoryBackup() { - return getResourceDir() + dictDirectoryBackup; + return getDictDirectoryPrefixDir() + dictDirectoryBackup; } - private String getResourceDir() { - //return hanlpPropertiesPath = HanlpHelper.getHanlpPropertiesPath(); - return ClassLoader.getSystemClassLoader().getResource("").getPath(); + private String getDictDirectoryPrefixDir() { + try { + return HanlpHelper.getHanlpPropertiesPath(); + } catch (FileNotFoundException e) { + log.warn("getDictDirectoryPrefixDir error: " + e); + e.printStackTrace(); + } + return ""; } } \ No newline at end of file