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;
}
path="d:\text\dd.doc";
String fileName = "";
while (true) {
File file = new File(path + fileName);
if (!file.exists()) {
break;
}
}
return fileName;
}
//取得当前文件夹下所有文件和目录的列表
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();
}
}
{
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;
}
}