Read resource directory file

  It is common to use maven to build the project in the project, but when using maven, some jars may fail to be downloaded due to unstable network, or the need for FQ and other factors, and the project can only be started normally by re-downloading.

How to quickly find which dependency is reporting an error? No more nagging, see the solution below

 

package cn.yunhwa.power.webservice;

import java.io. *;
import java.util. *;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
*
* @Title: TestIo
* @Description: Obtain the required resources by reading the path of the specified file name in the specified directory and subdirectory, and the returned result is List
* @author: lijunwei
* @date May 2018 8th 9:29:35 PM
*/
public class TestIo {

private static Logger logger = LoggerFactory.getLogger (TestIo.class);

/**
*
* @Title: getListFiles
* @Description: Get the resource files in the directory by specifying the path, suffix, and whether to loop through subdirectories
* @author: lijunwei
* @date May 8, 2018 at 8:33 pm :31
* @param path file path
* @param suffix suffix name, if it is empty, it means all files
* @param flag whether to traverse subdirectories
* @return List<String>
* @version
* @since
* @throws
*/
public static List <String> getFilesList(String path, String suffix, boolean flag) {
List<String> lstFileNames = new ArrayList<String>();
File file = new File(path);
return TestIo.listFile(lstFileNames, file, suffix, flag );
}

// aether-ed239b5e-5ab7-49c1-8f71-df76605fb76e-spring-beans-5.0.5.RELEASE.jar.sha1-in-progress
// The dependencies ending with in-progress are download failure dependencies, common download dependencies Failed suffix, .sha1-in-progress/.jar-in-progress/.pom-in-progress
private static List<String> listFile(List<String> lstFileNames, File f, String suffix, boolean flag) {
// If it is a directory, recursively traverse the subdirectories
if (f.isDirectory()) {
File[] t = f.listFiles();

for (int i = 0; i < t.length; i++) {
if (flag || t[i].isFile()) {
listFile(lstFileNames, t[i], suffix, flag);
}
}
} else {
String filePath = f.getAbsolutePath();
if (!suffix.equals("")) {
int begIndex = filePath.lastIndexOf("."); // 最后一个.(即后缀名前面的.)的索引
String tempsuffix = "";

if (begIndex != -1) {// Here you can filter files with the specified suffix
tempsuffix = filePath.substring(begIndex + 1, filePath.length());
// sha1-in-progress includes in-progress
// here because The specified suffix is ​​inconsistent with the suffix of intercepted ., so add a || tempsuffix.contains(suffix) condition
if (tempsuffix.equals(suffix) || tempsuffix.contains(suffix)) {
lstFileNames.add(filePath);
}
}
} else {
lstFileNames.add(filePath);
}
}
return lstFileNames;
}

public static void main(String[] args) {
List<String> list = getFilesList("G:\\repository", "in-progress", true);
logger.debug("Depending on the number of download failures: {} ",list.size());
logger.info("Dependency download failed dependency directory: {}",list);
}
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325845510&siteId=291194637