2017-10-04 12 views
-8

여기에 거의 문제가 없습니다. 이 포함될 수있는 디렉토리 내의 모든 파일을 특정 단어로 찾아야합니다. 이제는 어떻게 작동해야할지 모르겠다. 단어로 된 파일을 찾을 수는 있지만 이름만으로는 부족하다.Java에서 부분 문자열로 파일 찾기

String path ="C:\...ecc..."; 
String fileName= "01"; 
File file = new File(path+fileName) 

    if(file.exists()){ 
    // stuff with file 
    } 

01에 이름이있는 파일을 찾고 대신 이름에 01이있는 모든 파일을 찾고 싶습니다. 어떤 아이디어? 디렉토리 esxists을 doesen't 경우

Boolean exist = false; 
    for(File file : listaFile){          
     if(file.getName().startsWith(valueDeep)){ 
      path+="/"+file.getName(); 
      attachFileAnagView.setLvl3(file.getName()); 
      exist = true; 
      } 
    } 

    if(!exist){ 
     new File(path+"/"+valueDeep).mkdir(); 
     path+="/"+valueDeep; 
     attachFileAnagView.setLvl3(valueDeep); 
    } 

, 그것은 새로운 만들기 :

+4

코드 공유 – pleft

+0

파일 이름이나 파일 내용에 대해 이야기하고 있습니까? – Kayaman

+0

당신이 가지고있는 문제는 무엇입니까? 너 뭐 해봤 니? – Stultuske

답변

-4

이이 (알록 싱의 작은 도움으로) 나는 해결책을 발견

File file=new File("D://folderName"); 
File files[]= file.listFiles(); 
for(File f:files){ 
    if(f.getName().contains("search word")){ 
     System.out.println(f.getName()); 
    } 
}