java.io.File中一些函数的学习
来源:互联网 发布:强行脱女朋友裤子知乎 编辑:程序博客网 时间:2024/06/06 23:51
Example
public static long diskUsage(File root){ long total = root.length(); if(root.isDirectory()){ for(String childname: root.list()){ File child = new File(root, childname); total += diskUsage(child); } } return total;}public static void main(String[] args){ System.out.println(diskUsage(new File("/Users/zhongwen/Desktop/ForDreamForFuture/mycode")));}
用到的Methods
new File(pathString) or new File(parentFile, childString)
A new File instance can be constructed either by providing the full path as a string,
or by providing an existing File instance that represents a directory and a string that designates the name of a child entry within that directory.
also,
File(String parent, String child)
Creates a new File instance from a parent pathname string and a child pathname string.file.length()
Returns the length of the file denoted by this abstract pathname.file.isDirectory()
Tests whether the file denoted by this abstract pathname is a directory.file.list()
Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname.
ps:在terminal中查看某个文件夹的disk usage的命令是 du -a filepath
- java.io.File中一些函数的学习
- java IO流中File类的学习笔记
- java的java.io.File的学习
- Java.io.File类的学习
- Java中IO流的File类
- java.io.File操作文件的一些常用方法
- JAVA\IO\File类学习
- java中File类的一些用法
- 【Java学习】Java IO-File类的理解和总结
- 黑马程序员--IO(File类、Properties、IO中其他的一些常用流、字符编码)
- Java IO学习札记(File类的使用)
- Java学习笔记之IO(一):File类的用法
- java.io.File中File.separator和File.pathSeparator的区别
- java.IO系统file类中createNewFile FileInputStream的思考
- 发现java.io.File中 list()方法的一个bug
- java中io与file的简单了解
- java.io.file 中mkdir和mkdirs的区别
- Java中IO流的使用方法之File
- iptables学习笔记:端口转发之“内网访问外网”
- Git实现从本地添加项目到远程仓库
- HBase写和读的机制
- Android之ViewHolder用法
- 设计模式--观察者模式
- java.io.File中一些函数的学习
- Po学校Mark老师教的打字母游戏
- android:inputType常用取值
- HDU 1506 City Game by Assassin
- 从1到n整数中1出现的次数:O(logn)算法
- hadoop 2.x之HDFS HA讲解之九HDFS HA测试启动服务进程、页面监控查看和解决问题
- jquery选择器
- java多线程设计模式之Immutable Pattern
- Mac上小巧实用的GIF格式录屏软件 LICEcap