2017-09-14 3 views

答えて

0
String findFileName(String containerName, String path){ 
    int counter=0; 
    String [] sa = path.split("\\\\"); 
    String res=""; 

    for(int i=0; i<sa.length; i++) 
    { 

     if(counter==3) 
      res+=sa[i]+" "; 
     if(sa[i].equals(containerName)) 
      counter++; 
     if(counter==3) 
      res+=sa[i]+" "; 
    } 

    return res.trim(); 
} 

\がエスケープする必要があることに注意してください。そう上記

findFileName("local","C:\\MyFiles\\User\\admin\\local\\toCopy\\local\\recentFiles\\local\\textFile\\textFile.txt")

と呼ばれ、それは

textFile textFile.txt

が返さなければなりません
関連する問題