目前假如有几个字符串为文件名
String s1="abcd";
String s2= "cdab";
String s3="cdabcd";  
输入 dir ab* 后 只找到ab开头的字符串, 
如“abcd”  s1字符串匹配
输入dir  *ab 只显示ab结尾的字符串
如“cdab”  s2 字符串匹配
和在 windows DOS下一样,
问题是  
如何在我输入 dir ab*之后找到是  s1这个字符串匹配 而s2 s3 不匹配
        输入 dir *ab之后找到是  s2这个字符串匹配 而s1 s3 不匹配

解决方案 »

  1.   

    提问前建议多看看java的api文档.
    String类有两个方法, startWith和endWith.
      

  2.   

    建议使用Runtime 这个类,可以执行dos,命令,并通过发挥的进程流进行筛选
      

  3.   

    建议使用jdk1.7新增的nio2提供的DirectoryStream。
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, "ab*")) {
               for (Path entry: stream) {
                   System.out.println(entry);
               }
           } catch (DirectoryIteratorException ex) {
               // I/O error encounted during the iteration, the cause is an IOException
               throw ex.getCause();
           }
      

  4.   

    这个像不?http://blog.csdn.net/zqfddqr/article/details/6745484