File类 判断功能和获取功能
生活随笔
收集整理的這篇文章主要介紹了
File类 判断功能和获取功能
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
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() 獲得文件的字節(jié)數(shù)
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 }
?
轉(zhuǎn)載于:https://www.cnblogs.com/zhangmenghui/p/10586323.html
總結(jié)
以上是生活随笔為你收集整理的File类 判断功能和获取功能的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一个整形数组中最大值求和问题(3)
- 下一篇: Servlet组件之一——Filter过