java: file

 

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
/**
 * 版权所有 2022 涂聚文有限公司
 * 许可信息查看:
 * 描述:
 * IDE:IntelliJ IDEA 2021.2.3
 * 数据库:MSSQL Server 2019
 * OS:windows 10 x64
 * 历史版本: JDK 14.02
 * 2022-1-12 创建者 geovindu
 * 2022-1-15 添加 Lambda
 * 2022-1-15 修改:date
 * 接口类 mssql-jdbc-9.4.1.jre16.jar.
 *
 * 2022-1-15 修改者:Geovin Du
 * 生成API帮助文档的指令:
 *javadoc - -encoding Utf-8 -d apidoc Filter.java
 
 * */
 
 
package Geovin.Common;
 
import java.io.File;
import java.io.*;
import java.io.FilenameFilter;
import java.util.*;
 
/**
 * 自定义文件扩展名过滤器
 * @author geovindu
 * @version 1.0
 *
 * */
public class Filter implements FilenameFilter {
 
    String extent;
 
    public Filter(String extent)
    {
        this.extent=extent;
    }
    /**
     *
     * @param dir 文件夹 名
     * @param name  文件扩展名
     * @return  bool
     *
     * */
    @Override
    public  boolean Accept(File dir,String name)
    {
        return  name.endsWith("."+extent);
 
    }
}

  

 

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
//Geovin Du geovindu
       File dir=new File("./TestDir");
       String ext="html";
      Geovin.Common.Filter filter=new Filter(ext);
      System.out.println(""+dir);
      String files[]=dir.list(filter);
      for(String fileName:files)
      {
          File file=new File(dir,fileName);
          if(file.isFile())
          {
              System.out.println("文件名:"+ file.getName());
              System.out.println("文件绝对路径:"+file.getAbsolutePath());
              System.out.println("文件路径:"+file.getPath());
              System.out.println("文件最后修改时间:"+file.lastModified());
              System.out.println("文件大小:"+file.length());
              System.out.println("是否存:"+file.exists());
              System.out.println("是否可写:"+file.canWrite());
 
          }
          else
          {
              System.out.println("子目录:"+file);
          }
      }
 
       Handler consoleHandler = null;
       Handler fileHandler  = null;
       try{
           //Creating consoleHandler and fileHandler
           consoleHandler = new ConsoleHandler();
           fileHandler  = new FileHandler("./javacodegeeks.log");
 
           //Assigning handlers to LOGGER object
           LOGGER.addHandler(consoleHandler);
           LOGGER.addHandler(fileHandler);
 
           //Setting levels to handlers and LOGGER
           consoleHandler.setLevel(Level.ALL);
           fileHandler.setLevel(Level.ALL);
           LOGGER.setLevel(Level.ALL);
 
           LOGGER.config("Configuration done.");
 
           //Console handler removed
           LOGGER.removeHandler(consoleHandler);
 
           LOGGER.log(Level.FINE, "Finer logged");
       }catch(IOException exception){
           LOGGER.log(Level.SEVERE, "Error occur in FileHandler.", exception);
       }
 
       LOGGER.finer("Finest example on LOGGER handler completed.");

  

 

posted @   ®Geovin Du Dream Park™  阅读(40)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示