欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

JAVA正則表達(dá)式過濾文件的實(shí)現(xiàn)方法-創(chuàng)新互聯(lián)

JAVA正則表達(dá)式過濾文件的實(shí)現(xiàn)方法

專注于為中小企業(yè)提供成都網(wǎng)站設(shè)計(jì)、做網(wǎng)站服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)沙坡頭免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了1000多家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。

  正則表達(dá)式過濾文件列表,聽起來簡單,如果用java實(shí)現(xiàn),還真需要一番周折,本文簡析2種方式 


1、適用于路徑確定,文件名時(shí)正則表達(dá)式的情況(jdk6的寫法)

String filePattern = "/data/logs/.+\\.log"; 
File f = new File(filePattern); 
File parentDir = f.getParentFile(); 
String regex = f.getName(); 
FileSystem FS = FileSystems.getDefault(); 
final PathMatcher matcher = FS.getPathMatcher("regex:" + regex); 
 
DirectoryStream.Filter<Path> fileFilter = new DirectoryStream.Filter<Path>() { 
 @Override 
 public boolean accept(Path entry) throws IOException { 
  return matcher.matches(entry.getFileName()) && !Files.isDirectory(entry); 
 } 
}; 
 
List<File> result = Lists.newArrayList(); 
try (DirectoryStream<Path> stream = Files.newDirectoryStream(parentDir.toPath(), fileFilter)) { 
 for (Path entry : stream) { 
  result.add(entry.toFile()); 
 } 
} catch (IOException e) { 
 e.printStackTrace(); 
} 
for(File file : result) { 
 System.out.println(file.getParent() + "/" + file.getName()); 
} 
 

分享標(biāo)題:JAVA正則表達(dá)式過濾文件的實(shí)現(xiàn)方法-創(chuàng)新互聯(lián)
轉(zhuǎn)載注明:http://www.chinadenli.net/article46/dijghg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供云服務(wù)器微信公眾號網(wǎng)站排名ChatGPT外貿(mào)網(wǎng)站建設(shè)定制開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運(yùn)營