I used this code to instantiate a File object:

File f = new File(path);

How do I get the size of this file?

What is the difference between getUsableSpace(), getTotalSpace(), and getFreeSpace()?

解决方案

Use the length() method in the File class. From the javadocs:

Returns the length of the file denoted by this abstract pathname. The return value is unspecified if this pathname denotes a directory.

For the second part of the question, straight from File's javadocs:

getUsableSpace() Returns the number of bytes available to this virtual machine on the partition named by this abstract pathname

getTotalSpace() Returns the size of the partition named by this abstract pathname

getFreeSpace() Returns the number of unallocated bytes in the partition named by this abstract path name

java 文件大小,如何在Java中获取文件大小相关推荐

  1. python中获取文件大小_如何在Python中获取文件大小

    python中获取文件大小 We can get file size in Python using the os module. 我们可以使用os模块在Python中获取文件大小. Python中的 ...

  2. 【转】Java中获取文件大小的正确方法

    [转]Java中获取文件大小的正确方法 本文出处:http://blog.csdn.net/chaijunkun/article/details/22387305,转载请注明.由于本人不定期会整理相关 ...

  3. java如何实取随机数_java - 如何在Kotlin中获取随机数?

    java - 如何在Kotlin中获取随机数? 可以在2个参数之间返回随机整数的通用方法,如ruby,可以使用rand(0..n). 有什么建议吗? 16个解决方案 208 votes 我的建议是In ...

  4. java+script+当前日期_如何在JavaScript中获取当前日期?

    如何在JavaScript中获取当前日期? #1楼 您可以使用扩展了 Date对象的Date.js库,从而可以使用.today()方法. #2楼 如果您想对日期格式进行更多的粒度控制,我强烈建议您查看 ...

  5. 在Python中获取文件大小? [重复]

    本文翻译自:Getting file size in Python? [duplicate] This question already has an answer here: 这个问题在这里已有答案 ...

  6. java数据存在ie中_[Java教程]解决在IE中获取数据的缓存问题,运行环境为node.js

    [Java教程]解决在IE中获取数据的缓存问题,运行环境为node.js 0 2015-11-30 20:00:06 IE下默认会开启缓存策略,不管是页面还是通过ajax请求的数据都会议一个url,u ...

  7. 如何在Activity中获取调用者 -- getReferrer()

    如何在Activity中获取调用者 – getReferrer() 前言 为什么要在Activity中获取调用者? 主要是安全和定制两个方面的需求吧. 安全需求: 一般Activity如果已经对外开放 ...

  8. 如何在PHP中获取客户端IP地址[重复]

    本文翻译自:How to get the client IP address in PHP [duplicate] This question already has an answer here: ...

  9. 如何在JavaScript中获取时间戳

    如何在JavaScript中获取时间戳 +运算符 我们可以使用+运算符将日期对象直接转换为UNIX时间戳. 例如,我们可以这样写: +new Date() +日期对象之前操作者触发valueOf的方法 ...

  10. 关于Activity的getReferrer():如何在Activity中获取调用者?

    http://blog.csdn.net/u013553529/article/details/53856800 关于Activity的getReferrer()之一:如何在Activity中获取调用 ...

最新文章

  1. 基于CNN目标检测方法(RCNN,Fast-RCNN,Faster-RCNN,Mask-RCNN,YOLO,SSD)行人检测,目标追踪,卷积神经网络
  2. Java synchronized 和 volatile 的区别
  3. python【蓝桥杯vip练习题库】 ADV-364 天天向上(DP)
  4. .net 显示时间为YYYY-MM-DD格式
  5. linux查找被杀死的进程,linux查找进程和杀死进程
  6. Java时间处理类SimpleDateFormat的parse和format方法的正确使用
  7. 数学推导题,NTT,快速数论变换,Wannafly-导数卷积
  8. 【文章】浅相遇,薄相知,淡相守,终难忘
  9. 求矩阵中各列数字的和
  10. 【C语言】文件程序设计实践
  11. 整数的素因数权重分析
  12. C#/.net 中的事件与代理
  13. centos下svn和Apache的结合使用
  14. 服务器机柜内手机信号,手机信号强度是什么
  15. 使用Beautiful Soup 中遇到的小问题-----只能提取网页上第一页信息
  16. Windows10中IE11浏览器的修复之路
  17. 《指弹:November.28th》
  18. 基于 Proteus 的单片机仿真
  19. 如何做好SQLite 使用质量检测,让事故消灭在摇篮里
  20. 清晰理解红黑树的演变---红黑的含义

热门文章

  1. linux常用文本编缉命令(strings/sed/awk/cut/uniq/sort)
  2. makefile从无到有
  3. 剑指 Offer 64. 求1+2+…+n(面试题中的短路与)
  4. Linux Socket之send()异步通信时:Broken pipe报错
  5. github项目下载与提交
  6. 我眼中的Android Framework
  7. Android java获取行号和函数名
  8. 启动Activity不显示界面
  9. 机器学习之工程师入门路线
  10. android之activity跳转