------- android培训、java培训、期待与您交流! ----------
下面是我以前工作中所用的的代码,挺有用的,希望对大家有所帮助。
在readFileName类中根据某文件路径得到文件路径下面的文件名称
public class readFileName {
public static void main(String[] args) {
// This is the path where the file's name you want to take.
String path = "D:/MShop";
getFile(path);
}
private static void getFile(String path){
// get file list where the path has
File file = new File(path);
// get the folder list
File[] array = file.listFiles();
for(int i=0;i<array.length;i++){
if(array[i].isFile()){
// take file path and name
System.out.print("文件路径" + array[i].getPath());
// only take file name
System.out.println("文件名: " + array[i].getName());
}else if(array[i].isDirectory()){
getFile(array[i].getPath());
}
}
}
学习永无止境,希望得到大家的支持!!!
------- android培训、java培训、期待与您交流! ---------- 详细请查看:http://edu.csdn.net/heima/