一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - java讀取某個文件夾下的所有文件實例代碼

java讀取某個文件夾下的所有文件實例代碼

2020-08-28 10:43Java教程網 Java教程

這篇文章主要介紹了java讀取某個文件夾下的所有文件實例代碼的相關資料,需要的朋友可以參考下

java讀取某個文件夾下的所有文件

         學習java基礎知識,讀取文件,讀取某個文件夾,需要讀取所有文件,如何實現呢,看下實例代碼。

實例代碼:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.File;
 
public class ReadFile {
    public ReadFile() {
    }
    /**
     * 讀取某個文件夾下的所有文件
     */
    public static boolean readfile(String filepath) throws FileNotFoundException, IOException {
        try {
 
            File file = new File(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 void main(String[] args) {
        try {
            readfile("e:/videos");
            // deletefile("D:/file");
        } catch (FileNotFoundException ex) {
        } catch (IOException ex) {
        }
        System.out.println("ok");
    }
 
}

原文鏈接:http://blog.csdn.net/devilnov/article/details/9996861

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 调教催眠改造np总攻 | 亚洲视频在线免费观看 | 日本高清中文字幕视频在线 | 精品性久久 | 成在线人免费视频一区二区三区 | 国产精品久久久久jk制服 | 色天天色综合 | 男人与禽交的方法 | 毛片的网站 | 精品视频 久久久 | 波多野结衣小说 | 国产欧美日韩精品高清二区综合区 | 亚洲狠狠综合久久 | 嗯好爽视频| 456老汉gay | 五月天精品在线 | 第一国内永久免费福利视频 | 俄罗斯激情性孕妇孕交大全 | 国产99久久九九精品免费 | 男女污网站 | 日本护士撒尿xxxx18 | 校园刺激全黄H全肉细节文 校草让我脱了内裤给全班看 | 成人免费公开视频 | 久久99re8热在线播放 | 亚洲国产精品久久久久久网站 | 国色天香 社区视频 | jm漫天堂破解版 | 欧美激情精品久久久久久不卡 | 日本老妇和子乱视频 | 天堂69亚洲精品中文字幕 | 亚洲欧美日韩成人 | 美女被狂干 | 九九精品视频一区二区三区 | 国产色司机在线视频免费观看 | 亚洲经典 | 国产成人一区二区三区小说 | 国产高清不卡视频在线播放 | 97porm自拍视频区原创 | 成人二区 | 亚洲视频在线观看免费 | 性欧美videofree中文字幕 |