Browse Source

Merge remote-tracking branch 'origin/write-file-error' into projects/gouli

lyhzzz 1 year ago
parent
commit
cc5235c543

+ 4 - 7
src/main/java/com/fdkankan/ucenter/service/impl/SceneCommonService.java

@@ -32,8 +32,6 @@ public class SceneCommonService {
     FYunFileServiceInterface fYunFileServiceInterface;
     @Autowired
     IScene3dNumService scene3dNumService;
-    @Autowired
-    com.fdkankan.ucenter.util.FileUtil fileUtil;
 
     public String getNewNum(String oldNum ){
         String newNum = scene3dNumService.generateSceneNum(1);
@@ -143,19 +141,18 @@ public class SceneCommonService {
                     if(fileName.contains("scene.json")){
                         JSONObject jsonObject = JSONObject.parseObject(newJson);
                         jsonObject.put("sceneName",newSceneName);
-                        fileUtil.writeFile(localPath,jsonObject.toJSONString());
+                        FileUtils.writeFile(localPath ,jsonObject.toJSONString());
                         String sceneJsonPath = String.format(SceneResourcePath.dataPath+"/"+fileName, newNum);
                         fYunFileServiceInterface.uploadFile(localPath, sceneJsonPath);
                     }else {
-                        fileUtil.writeFile(localPath,newJson);
+                        FileUtils.writeFile(localPath ,newJson);
                     }
 
-
                 }
                 if("v4".equals(sceneVersion)){
                     JSONObject jsonObject = JSONObject.parseObject(newJson);
                     jsonObject.put("title",newSceneName);
-                    fileUtil.writeFile(localPath,jsonObject.toJSONString());
+                    FileUtils.writeFile(localPath, jsonObject.toJSONString());
 
                     String sceneJsonPath = String.format(SceneResourcePath.DATA_VIEW_PATH+"/" + fileName, newNum);
                     fYunFileServiceInterface.uploadFile(localPath, sceneJsonPath);
@@ -196,7 +193,7 @@ public class SceneCommonService {
         if(StringUtils.isNotBlank(fileContent)){
             String newJson = fileContent.replaceAll(oldNum,newNum);
             try {
-                fileUtil.writeFile(localPath,newJson);
+                FileUtils.writeFile(localPath, newJson);
                 fYunFileServiceInterface.uploadFile(localPath,ossStatusJsonPath);
             }catch (Exception e){
                 log.error("writeFile-error:{}",e);

+ 0 - 40
src/main/java/com/fdkankan/ucenter/util/FileUtil.java

@@ -1,40 +0,0 @@
-package com.fdkankan.ucenter.util;
-
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Component;
-
-import java.io.*;
-
-@Slf4j
-@Component
-public class FileUtil {
-
-    public  void writeFile(String filePath,String str) {
-        FileOutputStream fos = null;
-        BufferedWriter bw = null;
-        try {
-            File fout = new File(filePath);
-            if(!fout.getParentFile().exists()){
-                fout.getParentFile().mkdirs();
-            }
-            if(!fout.exists()){
-                fout.createNewFile();
-            }
-            fos = new FileOutputStream(fout);
-            bw = new BufferedWriter(new OutputStreamWriter(fos));
-            bw.write(str);
-        }catch (Exception e){
-            log.info("writeFile:error:{}",e);
-        }finally {
-            if(bw != null){
-                try {
-                    bw.close();
-                    fos.close();
-                }catch (Exception e){
-                    log.info("writeFile:close-error:{}",e);
-                }
-            }
-        }
-
-    }
-}