File类 判断功能和获取功能

 1 package cn.zmh.File;
 2 
 3 import java.io.File;
 4 /*
 5 *
 6 * File判断功能
 7 *
 8 * */
 9 public class FileDemo3判断功能 {
10     public static void main(String[] args) {
11         fun1();
12     }
13     // 判断封装的路径是不是文件夹
14     public static void fun(){
15         File file = new File("d:\eclipse");
16         //判断eclipse 是否存在
17         if(file.exists()){
18             //如果存在  是文件夹的话  输出true
19             boolean directory = file.isDirectory();
20             System.out.println(directory);
21         }
22     }
23     //判断路径是否存在  exists();
24     public static void fun1(){
25         File file1 = new File("src");
26         boolean exists = file1.exists();
27         System.out.println(exists);
28     }
29 }
 1 package cn.zmh.File;
 2 
 3 import java.io.File;
 4 
 5 public class FileDemo4获取功能 {
 6     public static void main(String[] args) {
 7         fun();
 8         fun1();
 9     }
10     // 获取功能  返回路径中  表示的文件或者文件名  获取路径中最后部分的名字
11     public static void fun(){
12         File file = new File("d:\abc\XMind.rar");
13         String name = file.getPath();
14         System.out.println(name);
15     }
16     // length()  获得文件的字节数
17     public static void fun1(){
18         File file = new File("d:\abc\XMind.rar");
19         long length = file.length();
20         System.out.println(length);
21     }
22 }
原文地址:https://www.cnblogs.com/zhangmenghui/p/10586323.html