java获取指定文件夹下的所有文件名
2016-08-04 11:20
381 查看
http://blog.csdn.net/tomorrowzm/article/details/3693653
package Test;
import java.io.File;
/**
* @author yinxm
* @version 1.0 2005/06/17
*
* This class can take file's path and file's name;
* you must give the path where you want to take the file.
*/
public class TakeFilePathAndName {
public static void main(String[] args) {
// This is the path where the file's name you want to take.
String path = "C://Documents and Settings//yinxm//デスクトップ//TestFile";
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()){
// only take file name
System.out.println("^^^^^" + array[i].getName());
// take file path and name
System.out.println("#####" + array[i]);
// take file path and name
System.out.println("*****" + array[i].getPath());
}else if(array[i].isDirectory()){
getFile(array[i].getPath());
}
}
}
}
package Test;
import java.io.File;
/**
* @author yinxm
* @version 1.0 2005/06/17
*
* This class can take file's path and file's name;
* you must give the path where you want to take the file.
*/
public class TakeFilePathAndName {
public static void main(String[] args) {
// This is the path where the file's name you want to take.
String path = "C://Documents and Settings//yinxm//デスクトップ//TestFile";
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()){
// only take file name
System.out.println("^^^^^" + array[i].getName());
// take file path and name
System.out.println("#####" + array[i]);
// take file path and name
System.out.println("*****" + array[i].getPath());
}else if(array[i].isDirectory()){
getFile(array[i].getPath());
}
}
}
}
相关文章推荐
- java同步数据时候处理生僻字
- 【javase复习】## day9 Collections Arrays ##
- java小技巧
- java map转bean
- Struts2输入校验
- spring-autowire机制
- 开启JAVA自学新篇章
- 开启JAVA自学新篇章
- java web 学习笔记(一)WEB开发技术发展
- JAVA字符串格式化-String.format()的使用
- Java重写和重载
- eclipse导入已经存在的workspace
- 消除eclipse中web项目js文件出现的红叉
- 浅析Java中的final关键字
- 实践每日记8-4
- 《深入体验java web 开发内幕》-1
- Java学习之equals()、hashCode()、identityHashCode()、toString()和==
- java 反射机制的应用
- 三分钟秒懂java注解
- 一步一步解析java集合框架HashMap源码(1)