您的位置:首页 > 职场人生

黑马程序员--01得到文件夹下的文件名代码

2012-09-05 20:38 246 查看
------- 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/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐