zoukankan      html  css  js  c++  java
  • 1、IO--File类

    在整个I/O包中

    唯一与文件本身有关的类就是File

    使用File类可以实现创建或删除文件等常用的操作

    要使用File类需要首先观察File类的构造方法

    public File(String pathname)

    在实例化File类时必须要设置好路径

    如在D盘中的test.txt文件则写成"d:\test.txt"

    "\表示一个““

    File类中方法

    相关的测试代码:

    public static void main(String[] args) throws IOException {
            //file代表文件或者目录
            File f = new File("d:\test.txt");
            f.createNewFile();
            
            //文件名相关
            //获取文件的文件名
            String fname = f.getName();
            System.out.println(fname);//test.txt
            //文件的绝对路径
            String path = f.getAbsolutePath();
            System.out.println(path);//d:	est.txt
            
            //为文件重命名
            //此时不仅重命名,原来的位置的文件也随之拷贝过去
            //f.renameTo(new File("d://aa.txt"));
           
           
            //文件的检测
            //检测文件是否纯在,返回的是Boolean值
            System.out.println(f.exists());//true
            //检验是否是文件
            System.out.println(f.isFile());//true
            //检验是否是文件夹
            System.out.println(f.isDirectory());//false
           
            //获取文件的常规信息
            //获取文件的长度
            System.out.println(f.length());//0
         
            //文件操作
            //创建文件
            File ff = new File("aa.txt");
            ff.createNewFile();
       
            //delete()   删除
            ff.delete();
            System.out.println(ff.exists());//false
        }

  • 相关阅读:
    ci
    RN开发杂记
    ‘100%’wuxiao
    Statezhong shiyong redux props
    assemble、compile、make、build和rebuild的关系
    promise
    React Native 通过navigation实现页面间传值
    react native redux
    js中 === 整形和字符串比较
    React Native 中使用Redux
  • 原文地址:https://www.cnblogs.com/Mrchengs/p/10808518.html
Copyright © 2011-2022 走看看