1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- package com.fdkankan.fusion.common.util;
- import java.io.*;
- import java.nio.file.Paths;
- import java.nio.file.StandardCopyOption;
- import static cn.hutool.core.util.ClassUtil.getClassLoader;
- public class FileWriterUtil {
- public static void writerJson(String tagPath,String fileName,String msg){
- try {
- File file = new File(tagPath);
- if(!file.exists()){
- file.mkdirs();
- }
- FileWriter fw = new FileWriter(tagPath +File.separator +fileName);
- fw.write(msg);
- fw.flush();
- fw.close();
- }catch (Exception e){
- e.printStackTrace();
- }
- }
- public static String readFile(String file) throws Exception {
- BufferedReader reader = new BufferedReader(new FileReader(file));
- String line = null;
- StringBuilder stringBuilder = new StringBuilder();
- String ls = System.getProperty("line.separator");
- try {
- while((line = reader.readLine()) != null) {
- stringBuilder.append(line);
- stringBuilder.append(ls);
- }
- return stringBuilder.toString();
- } finally {
- reader.close();
- }
- }
- public static void streamToFile(String fileName,String newFilePath){
- InputStream stream = getClassLoader().getResourceAsStream(fileName);
- try {
- assert stream != null;
- java.nio.file.Files.copy(
- stream,
- Paths.get(newFilePath),
- new StandardCopyOption[]{StandardCopyOption.REPLACE_EXISTING});
- }catch (Exception e){
- e.printStackTrace();
- }
- }
- public static File getObjLasPlyFile(File objPathFile) {
- if(objPathFile.isDirectory()){
- File[] file = objPathFile.listFiles();
- if(file == null || file.length <=0){
- return null;
- }
- for (File file1 : file) {
- if(file1 == null){
- continue;
- }
- if(file1.isDirectory()){
- return getObjLasPlyFile(file1);
- }
- if(file1.getName().contains("obj") || file1.getName().contains("ply") || file1.getName().contains("las")){
- return file1;
- }
- }
- }
- return null;
- }
- }
|