提交 ed511cc3 authored 作者: 孙洁清's avatar 孙洁清

遍历文件

上级 51a427eb
package com.zjty.autotest.service;
import com.zjty.autotest.pojo.sjq.common.ResponseResult;
public interface HtmlFileService {
public ResponseResult getRoutes(String fileAddress);
}
package com.zjty.autotest.service.impl;
import com.zjty.autotest.pojo.sjq.common.ResponseResult;
import com.zjty.autotest.service.HtmlFileService;
import org.springframework.stereotype.Service;
@Service
public class HtmlFileServiceImpl implements HtmlFileService {
@Override
public ResponseResult getRoutes(String fileAddress) {
return null;
}
}
package com.zjty.autotest.util;
import java.io.File;
public class FileHtmlUtil {
public static void getFileRoutes(String path){
File file = new File(path);
// 如果这个路径是文件夹
if (file.isDirectory()) {
// 获取路径下的所有文件
File[] files = file.listFiles();
for (int i = 0; i < files.length; i++) {
// 如果还是文件夹 递归获取里面的文件 文件夹
if (files[i].isDirectory()) {
System.out.println("目录:" + files[i].getPath());
getFileRoutes(files[i].getPath());
} else {
System.out.println("文件名:" + files[i].getName());
System.out.println("文件:" + files[i].getPath());
}
}
} else {
System.out.println("文件:" + file.getPath());
}
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论