zoukankan      html  css  js  c++  java
  • 关于File的应用(File可以封装文件夹等等)获取一些文件的信息

    package test;
    
    
    import java.io.*;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.*;
    import java.util.zip.InflaterInputStream;
    
    import javax.annotation.processing.FilerException;
    
    import privateclass.MyBufferedReader;
    
    public class Main {
    
    	private static final String space_operator = " ";
    	private static final double pi = Math.PI;
    	private static final String LINE_SEPARATOR = System.getProperty("line.separator");
    	public static void main(String[] args) throws Exception {
    
    		//File.separator 是分区的分隔符  这个分隔符在windows下是\在linux下是/
    		File file = new File("E:"+File.separator+"java编译\test\demo.txt");//绝对路径
    		////File file = new File("demo.txt");//相对路径
    		System.out.println(file);
    		String name = file.getName();
    		//剩余空间大小
    		long free = file.getFreeSpace();
    		//文件的大小
    		long len = file.length();
    		//文件的最后修改时间
    		long time = file.lastModified();
    		
    		//文件的绝对路径
    		String abspath = file.getAbsolutePath();
    		//文件的相对路径
    		String path = file.getPath();
    		
    		DateFormat dateFormat = new SimpleDateFormat("yyyy MM dd");
    		DateFormat dateFormat2 = DateFormat.getDateTimeInstance(DateFormat.LONG,dateFormat.LONG);
    		System.out.println("name:" + name);
    		System.out.println("time:" + dateFormat.format(new Date(time)));
    		System.out.println("time:" + dateFormat2.format(new Date(time)));
    		System.out.println("free:" + free);
    		System.out.println("len:" + len);
    		System.out.println("abspath:" + abspath);
    		System.out.println("path:" + path);
    	}
    }
    

      

  • 相关阅读:
    什么是进程!
    【2016.5.9】不考研,那就好好学
    ajax的秘密
    Input标签中Type的类型及详细用法
    html5 Canvas颜色渐变(画图很重要)
    页面的自动滚动效果
    HTML:让表单 文本框 只读,不可编辑的方法
    <s:property/>标签
    在HTML中实现上划线,中划线和下划线
    Mysql的Root密码忘记,查看或修改的解决方法(图文介绍)
  • 原文地址:https://www.cnblogs.com/WINDZLY/p/11809511.html
Copyright © 2011-2022 走看看