黑马程序员--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/
下面是我以前工作中所用的的代码,挺有用的,希望对大家有所帮助。
在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/
相关文章推荐
- 得到指定文件夹内文件名
- C# 里怎样得到当前执行的函数名,当前代码行,源代码文件名
- C# 遍历文件夹下所有子文件夹中的文件,得到文件名
- 小工具:得到目标文件夹中文件名 python
- 获取项目加载根路径,得到文件夹下的所有指定后缀文件名列表
- C# 遍历文件夹下所有子文件夹中的文件,得到文件名
- How To Get Application Path,And How To Get The Path's Directory,File Name,And Type Info(如何得到运行程序的路径,以及如何得到路径的文件夹,文件名,以及类型等等信息)
- 一段代码得到本页面的文件名
- 黑马程序员——OCFoundation框架-9:计算某个文件夹下的代码行数
- 如何得到运行程序的路径,以及如何得到路径的文件夹,文件名,以及类型等等信息
- C# 里怎样得到当前执行的函数名,当前代码行,源代码文件名。
- C# 里怎样得到当前执行的函数名,当前代码行,源代码文件名。
- C# 里怎样得到当前执行的函数名,当前代码行,源代码文件名。
- C# 里怎样得到当前执行的函数名,当前代码行,源代码文件名
- 如何用python快速得到文件夹下面的文件名和路径
- 读取文件夹里面的文件名代码
- 利用DIR命令批量输出文件夹名或文件名的代码
- android代码中读取文件夹下的文件名
- c++ 得到文件夹下所有文件的文件名和文件夹下所有文件夹名
- C# 里怎样得到当前执行的函数名,当前代码行,源代码文件名。