File Path使用

tech2023-11-02  105

/** * 创建文件夹 */ public static boolean createDirectories(Path path) { if (!Files.exists(path)) { try { Files.createDirectories(path); } catch (IOException e) { log.error(path.toString() + " 文件夹创建失败"); e.printStackTrace(); return false; } } return true; } StringBuilder basePath = new StringBuilder() .append(EXCEL_FILE_LOCATION).append(id).append(File.separator) .append(userId).append(File.separator); Path path = Paths.get(basePath.toString()); FileUtil.createDirectories(path); Path resolve = path.resolve(DateTimeUtil.timeStamp2String(System.currentTimeMillis(), "yyyyMMdd-HHmmss") + fs.getFileName()); Files.copy(fs.getFileStream(), resolve, StandardCopyOption.REPLACE_EXISTING); //策略模式 选择对应模板 解析入库保存 ExcelParseConstruct.getExcelParseStrategy("1").excelModelStrategy(); //获取路径 String toRealPath = resolve.toRealPath(LinkOption.NOFOLLOW_LINKS).toString();
最新回复(0)