当前位置: 首页 > news >正文

比较简洁大方的网站1+官网商城

比较简洁大方的网站,1+官网商城,德州网络推广,徽信小程序是什么序言 需要读取sftp服务器上符合指定的文件名正则的文件列表#xff0c;目前想到的最好的办法就是递归。 我这里引入的依赖是#xff1a; !-- jsch-sftp连接 --dependencygroupIdcom.jcraft/groupIdartifactIdjsch/artif…序言 需要读取sftp服务器上符合指定的文件名正则的文件列表目前想到的最好的办法就是递归。 我这里引入的依赖是 !-- jsch-sftp连接 --dependencygroupIdcom.jcraft/groupIdartifactIdjsch/artifactIdversion0.1.54/version/dependency不废话直接上代码 public static ListString getFileList(ChannelSftp channelSftp, String path, String fileNamePattern, Integer filePathDepth) {ListString fileList Lists.newLinkedList();try {Pattern pattern Pattern.compile(fileNamePattern);VectorChannelSftp.LsEntry files channelSftp.ls(path);//读取的根路径下一级就是文件if (1 filePathDepth) {for (ChannelSftp.LsEntry entry : files) {String fileName entry.getFilename();//找到和规则文件名正则匹配的文件if (pattern.matcher(fileName).matches()) {//拼接全路径String fullPath path fileName;fileList.add(fullPath);}}} else {//从读取根路径下开始算目录深度时目录深度大于1就使用递归来读取文件列表manyDirFileList(channelSftp, path, fileNamePattern, fileList, bComFilesaveReadruleDO.getDirPattern());}} catch (Exception e) {log.error(获取sftp指定目录下的文件列表失败{}, e.getMessage());}return fileList;}/*** 递归获取提供的路径下多级目录下符合正则的所有文件** param channelSftp ftp对象* param path 路径* param fileList 文件列表**/public static void manyDirFileList(ChannelSftp channelSftp, String path, String fileNamePattern,ListString fileList, String dirPattern) throws Exception {try {ListPattern dirPatterns new ArrayList();if (StringUtils.isNotEmpty(dirPattern)) {for (String pat : dirPattern.split(,)) {dirPatterns.add(Pattern.compile(pat.trim()));}}Pattern fileNamePat Pattern.compile(fileNamePattern);if (isDirectory(channelSftp, path)) {Vector? vector channelSftp.ls(path);for (Object l : vector) {ChannelSftp.LsEntry file (ChannelSftp.LsEntry) l;String fileName file.getFilename();boolean isDirMatch dirPatterns.isEmpty();for (Pattern dirPat : dirPatterns) {if (dirPat.matcher(fileName).matches()) {isDirMatch true;break;}}if (fileName.equals(.) || fileName.equals(..)) {continue;}if (isDirMatch || fileNamePat.matcher(fileName).matches()) {String fullPath path fileName (file.getAttrs().isDir() ? / : );manyDirFileList(channelSftp, fullPath, fileNamePattern, fileList, dirPattern);}}} else {String fileName path.substring(path.lastIndexOf(/) 1);if (fileNamePat.matcher(fileName).matches()) {fileList.add(path);}}} catch (SftpException e) {log.error(获取FTP指定目录下的文件异常路径{}异常信息{}, path, e.getMessage());} catch (Exception e) {log.error(递归获取SFTP指定目录下的文件列表失败路径{}异常信息{}, path, e.getMessage());throw new Exception(递归获取SFTP指定目录下的文件列表失败路径 path 异常信息 e.getMessage());}}另外还有一个需求就是只读取10个文件 public static ListString getFileListFor10(ChannelSftp channelSftp, String path, String fileNamePattern, Integer filePathDepth) {ListString fileList Lists.newLinkedList();try {Pattern pattern Pattern.compile(fileNamePattern);VectorChannelSftp.LsEntry files channelSftp.ls(path);//读取的根路径下一级就是文件if (1 filePathDepth) {for (ChannelSftp.LsEntry entry : files) {if (fileList.size() 10) {log.info(已读取10个文件不再读取目录:{}下的文件, path);break;}String fileName entry.getFilename();//找到和规则文件名正则匹配的文件if (pattern.matcher(fileName).matches()) {//拼接全路径String fullPath path fileName;fileList.add(fullPath);}}} else {//从输入的根路径下开始算目录深度时目录深度大于1就使用递归来读取文件列表manyDirFileListFor10(channelSftp, path, fileNamePattern, fileList, bComFilesaveReadruleDO.getDirPattern());}} catch (Exception e) {log.error(获取sftp指定目录下的文件列表失败{}, e.getMessage());}return fileList;}/*** 递归获取提供的路径下多级目录下符合正则的前10个文件** param channelSftp ftp对象* param path 路径* param fileList 文件列表**/public static void manyDirFileListFor10(ChannelSftp channelSftp, String path, String fileNamePattern,ListString fileList, String dirPattern) {try {ListPattern dirPatterns new ArrayList();if (StringUtils.isNotEmpty(dirPattern)) {for (String pat : dirPattern.split(,)) {dirPatterns.add(Pattern.compile(pat.trim()));}}Pattern fileNamePat Pattern.compile(fileNamePattern);if (isDirectory(channelSftp, path)) {Vector? vector channelSftp.ls(path);for (Object o : vector) {// 如果已经找到了10个文件直接返回不再递归if (fileList.size() 10) {log.info(已读取10个文件不再读取目录:{}下的文件, path);break;}ChannelSftp.LsEntry file (ChannelSftp.LsEntry) o;String fileName file.getFilename();boolean isDirMatch dirPatterns.isEmpty();for (Pattern dirPat : dirPatterns) {if (dirPat.matcher(fileName).matches()) {isDirMatch true;break;}}if (fileName.equals(.) || fileName.equals(..)) {continue;}if (isDirMatch || fileNamePat.matcher(fileName).matches()) {String fullPath path fileName (file.getAttrs().isDir() ? / : );manyDirFileListFor10(channelSftp, fullPath, fileNamePattern, fileList, dirPattern);}}} else {String fileName path.substring(path.lastIndexOf(/) 1);if (fileNamePat.matcher(fileName).matches()) {fileList.add(path);}}} catch (SftpException e) {log.error(获取FTP指定目录下的文件异常路径{}异常信息{}, path, e.getMessage());} catch (Exception e) {log.error(递归获取SFTP指定目录下的文件列表失败路径{}异常信息{}, path, e.getMessage());}}-----------------知道的越多, 不知道的越多--------------------
http://www.hkea.cn/news/14376359/

相关文章:

  • 网站建设预览wordpress 网址站
  • 做推广网站的文章网站的域名都有哪些
  • 婚纱网站设计代码htmlhtml做的小网站
  • 中国小康建设网是骗子网站吗?微信公众号开发文档
  • 自己做的网站可以买东西吗html5制作网站谁的好
  • 手机网站开发 .net网站 建设网站
  • 网站建设员课程西楚房产网宿迁房产网
  • dede鲜花网站模板下载邢台163招聘最新信息
  • 网站布局优化怎么做注册公司流程和费用
  • 广州做网站系统黄山旅游攻略ppt
  • 做网站找外包好吗宁波模板建站代理
  • 驾校网站建设费用php会了 怎么做网站
  • 汉中公司网站建设江苏网站建设哪家好
  • 让别人做网站图片侵权湖北省住房建设厅网站
  • 天津网站建设制作系统wordpress网站主修改密码
  • 廉洁 网站建设西安网站开发公司怎么选
  • 加强文明网站建设营销型网站建设要求
  • 深圳专业做网站案例专业微信网站建设公司首选公司
  • 网站开发需求分析实例深圳建设集团招标
  • php 企业网站模板 想1示范高职院校建设专题网站
  • 有备案号的网站是公司的吗网上购物网站建设论文
  • 广东哪有做网赌网站太仓网站优化
  • 珠海市网站建设开发公司短视频推广员干嘛的
  • wordpress memcache国际站seo优化是什么意思
  • 莞城网站仿做郑州知名网站建设服务公司
  • 婚庆网站模板下载暴雪战网怎么改国际服
  • 传奇做网站南宁企业网页设计
  • 西安微官网自助建站公司总裁培训班
  • 信誉比较好的商家可做网站怎么查在哪个网站做的备案
  • 网站建设容易出现的问题网站建设需要经历什么步骤