遍历指定路径下文件夹中的所有文件
String path = "[AbsolutePath]";
File file = new File(path);
File[] files = file.listFiles();
for (File file1 : files) {
try {
//获取pdf文件的bytes
byte[] bytes = PdfUtils.fileToBytes(file1.getAbsolutePath());
} catch (Exception e) {
logger.error(e, e.getMessage());
}
}
File file = new File("file path");
Strinf[] list = file.list();
for(String fileName: list){
}
剪切文件名中含有特定字符的文件
public static void main(String[] args){
tra{
String srcPath = "./src/";
String dstPath = "./tar/";
File files = new File(srcPath);
String] list = files.list;
for(String fileName : list){
if(fileName.contains("_")){
Path sPath = Paths.get(srcPath + fileName);
Path dPath = Paths.get(dstPath + fileName);
Files.move(sPath, dPath, StandardCopyOption.RePLACE_EXISTING);
}
}
} catch(Exception e){
e.printStackTreac();
}
}