package test1;
import java.io.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://Users//Administrator//Desktop//updateorderid//www";
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 获取文件的路径 名称
最新推荐文章于 2022-09-20 13:40:51 发布