zoukankan      html  css  js  c++  java
  • File类获取功能的方法

    /*
    getAbsolutePath()
            返回此抽象路径名的绝对路径名字符串。
    getPath()
            将此抽象路径名转换为一个路径名字符串。
    getName()
            返回由此抽象路径名表示的文件或目录的名称。
    length()
            返回由此抽象路径名表示的文件的长度。
    
            */
    
    import java.io.File;
    
    
    public class Demo03File {
        public static void main(String[] args) {
            show01();
            show02();
            show03();
            show04();
    
    
        }
    
        private static void show04() {//文件夹是没有大小概念的
            File f1=new File("C:\Users\cy\Desktop\1.jpg");
            File f2=new File("C:\Users\cy\Desktop\2.jpg");
            File f3=new File("C:\Users\cy\Desktop\miniprogram-2");
            long length = f1.length();
            long length1 = f2.length();
            long length2 = f3.length();
            System.out.println(length);
            System.out.println(length1);
            System.out.println(length2);
    
        }
    
        private static void show03() {//结尾部分文件或文件夹名
            File f1=new File("C:\Users\cy\Desktop\list.txt");
            String name1=f1.getName();
            System.out.println(name1);//list.txt
            File f2=new File("C:\Users\cy\Desktop");
            String name2 = f2.getName();
            System.out.println(name2);//Desktop
    
        }
    
        private static void show02() {
            File f1=new File("C:\Users\cy\Desktop\list.txt");
            File f2=new File("list.txt");
            String path1 = f1.getPath();
            System.out.println(path1);//C:UserscyDesktoplist.txt
    
            String path2 = f2.getPath();
            System.out.println(path2);//list.txt
    
            System.out.println(f1.toString());//调用getpath方法  C:UserscyDesktoplist.txt
    
        }
    
        private static void show01() {
            File f1=new File("C:\Users\cy\Desktop\list.txt");
            String absolutePath = f1.getAbsolutePath();
            System.out.println(absolutePath);
    
    
            File f2=new File("list.txt");
            String absolutePath1 = f2.getAbsolutePath();
            System.out.println(absolutePath1);
    
        }
    }
  • 相关阅读:
    Docker安装IBM MQ
    Spark On Yarn搭建及各运行模式说明
    Hadoop2.0之YARN组件
    HBase记录
    Spark对接Kafka、HBase
    SparkStreaming个人记录
    Java解决异常之try、catch、finally、throw、throws&log4j记录日志步骤
    Java访问权限修饰符public protected friendly private用法总结(转载好文Mark)
    租赁车辆(多车)程序
    考试答案对应
  • 原文地址:https://www.cnblogs.com/cy2268540857/p/13767145.html
Copyright © 2011-2022 走看看