public String getFileName(String path, String ext) {
    path="d:\text\dd.doc";
    String fileName = "";
    while (true) {
          File file = new File(path + fileName);
      if (!file.exists()) {
        break;
      }
    }
    return fileName;
  }

解决方案 »

  1.   

    File d = new File(paths);
        //取得当前文件夹下所有文件和目录的列表
        File lists[] = d.listFiles();
        String pathss = new String("");    //对当前目录下面所有文件进行检索
        for (int i = 0; i < lists.length; i++) {
          if (lists[i].isFile()) {
            String filename = lists[i].getName();
            }
         }
      

  2.   

    不是这样的。这里只是一个字符串。是求出一个包含路径字符串中的文件名。并没有给你文件File。再求。
      

  3.   

    class T
    {
    public static void main(String [] args){
    System.out.println(getFileName("d:\\text\\dd.doc"));
    }
    public static String getFileName(String path) {
        //path="d:\\text\\dd.doc";    //path 你可以传进来,这里就是你给出的文件路径
        String fileName = "";
        if(path!=null&&path.length()!=0){
            fileName = path.substring(path.lastIndexOf("\\")+1);
        }     
        return fileName;
        }
    }
      

  4.   

    dennis_he(1/2)  能行的通!