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);
    
        }
    }
  • 相关阅读:
    ckeditor详解
    c#实现生产者消费者模式
    逻辑思维题01
    关于nginx的安装
    一些关于python的小感想
    关于linux上pdf阅读器
    将python2.7+django1.10部署到SAE上
    配置github上的SSH key及上传自己的项目到github
    解决ubuntu15 下没有声音
    linux小倒腾
  • 原文地址:https://www.cnblogs.com/cy2268540857/p/13767145.html
Copyright © 2011-2022 走看看