当前位置:
首页 >
File类 判断功能和获取功能
发布时间:2025/6/17
39
豆豆
生活随笔
收集整理的这篇文章主要介绍了
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
总结
以上是生活随笔为你收集整理的File类 判断功能和获取功能的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 一个整形数组中最大值求和问题(3)
- 下一篇: Servlet组件之一——Filter过