日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

java读取文件夹_Java读取某个文件夹下的所有文件(支持多级文件夹)

發布時間:2024/7/23 java 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java读取文件夹_Java读取某个文件夹下的所有文件(支持多级文件夹) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

packagecom.vocy.water.batch;importjava.io.FileNotFoundException;importjava.io.IOException;importjava.io.File;public classCopyOfReadFile {publicCopyOfReadFile() {

}/*** 讀取某個文件夾下的所有文件(支持多級文件夾)*/

public static boolean readfile(String filepath) throwsFileNotFoundException, IOException {try{

File file= newFile(filepath);if (!file.isDirectory()) {

System.out.println("文件");

System.out.println("path=" +file.getPath());

System.out.println("absolutepath=" +file.getAbsolutePath());

System.out.println("name=" +file.getName());

}else if(file.isDirectory()) {

System.out.println("文件夾");

String[] filelist=file.list();for (int i = 0; i < filelist.length; i++) {

File readfile= new File(filepath + "\\" +filelist[i]);if (!readfile.isDirectory()) {

System.out.println("path=" +readfile.getPath());

System.out.println("absolutepath=" +readfile.getAbsolutePath());

System.out.println("name=" +readfile.getName());

}else if(readfile.isDirectory()) {

readfile(filepath+ "\\" +filelist[i]);

}

}

}

}catch(FileNotFoundException e) {

System.out.println("readfile() Exception:" +e.getMessage());

}return true;

}/*** 刪除某個文件夾下的所有文件夾和文件*/

/*public static boolean deletefile(String delpath)

throws FileNotFoundException, IOException {

try {

File file = new File(delpath);

if (!file.isDirectory()) {

System.out.println("1");

file.delete();

} else if (file.isDirectory()) {

System.out.println("2");

String[] filelist = file.list();

for (int i = 0; i < filelist.length; i++) {

File delfile = new File(delpath + "\\" + filelist[i]);

if (!delfile.isDirectory()) {

System.out.println("path=" + delfile.getPath());

System.out.println("absolutepath="

+ delfile.getAbsolutePath());

System.out.println("name=" + delfile.getName());

delfile.delete();

System.out.println("刪除文件成功");

} else if (delfile.isDirectory()) {

deletefile(delpath + "\\" + filelist[i]);

}

}

file.delete();

}

} catch (FileNotFoundException e) {

System.out.println("deletefile() Exception:" + e.getMessage());

}

return true;

}*/

public static voidmain(String[] args) {try{

readfile("d:/files");//deletefile("D:/file");

} catch(FileNotFoundException ex) {

}catch(IOException ex) {

}

System.out.println("ok");

}

}

總結

以上是生活随笔為你收集整理的java读取文件夹_Java读取某个文件夹下的所有文件(支持多级文件夹)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。