如何在android中获取临时文件的文件大小? [英] how do I get file size of temp file in android?

查看:285
本文介绍了如何在android中获取临时文件的文件大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用openFileOutput()来创建和写入临时文件,在写完文件后如何获取文件大小?

if I use openFileOutput() to create and write to a temp file how do I get filesize after I'm done writing to it?

推荐答案

我希望这可以帮到你:

File file = new File(selectedPath);
int file_size = Integer.parseInt(String.valueOf(file.length()/1024));

字符串 selectedPath 是路径要确定其文件大小的文件。

Where the String selectedPath is the path to the file whose file size you want to determine.

file.length()返回文件的长度字节,如 Java 7文档中所述

file.length() returns the length of the file in bytes, as described in the Java 7 Documentation:


返回此抽象路径名表示的文件的长度(以字节为单位),如果文件不是,则返回0L存在。某些操作系统可能返回0L表示路径名,表示依赖于系统的实体,例如设备或管道。

Returns the length, in bytes, of the file denoted by this abstract pathname, or 0L if the file does not exist. Some operating systems may return 0L for pathnames denoting system-dependent entities such as devices or pipes.

除以1024将大小从字节转换为千字节。

Dividing by 1024 converts the size from bytes to kilobytes.

这篇关于如何在android中获取临时文件的文件大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆