zoukankan      html  css  js  c++  java
  • java学习_File属性处理

    // TODO Auto-generated method stub
    File file=new File("newhello.txt");
    //文件是否存在
    System.out.println("文件是否存在:"+file.exists());
    //读取文件名称
    System.out.println("读取文件名:"+file.getName());
    //读取文件路径
    System.out.println("读取文件相对路径:"+file.getPath());
    //读取文件绝对路径
    System.out.println("读取文件绝对路径:"+file.getAbsolutePath());
    //获取文件父级路径 如果创建文件中上级为空 则结果为null
    System.out.println("获取文件父级路径:"+file.getParent());
    System.out.println("获取文件父级路径2:"+new File(file.getAbsolutePath()).getParent() );
    //读取文件大小
    System.out.println("读取文件大小:"+(float)file.length()/1024+"KB");
    //判断文件是否被隐藏
    System.out.println("判断文件是否被隐藏:"+file.isHidden());
    //判断文件是否可读
    System.out.println("判断文件是否可读:"+file.canRead());
    //判断文件是否可写
    System.out.println("判断文件是否可写:"+file.canWrite());
    //判断文件是否为文件夹
    System.out.println("判断文件是否为文件夹:"+file.isDirectory());

    //设置文件属性
    //设置文件为只读
    file.setReadOnly();
    //设置为可写
    file.setWritable(true);
    //设置为可读
    file.setReadable(true);

  • 相关阅读:
    视频质量诊断之详解
    Leetcode 22.生成括号对数
    leetcode 19.删除链表的第n个节点
    Leetcode 11.盛最多水的容器
    Leetcode 6.Z字形变换
    Leetcode 4.两个排序数组的中位数
    Leetcode 3.无重复字符的最长子串
    Leetcode 1.两数之和
    RNN and Language modeling in TensorFlow
    Tensorflow word2vec+manage experiments
  • 原文地址:https://www.cnblogs.com/fanmiao/p/4919710.html
Copyright © 2011-2022 走看看