有的时候需要获取手机中某个文件的大小,比如zip包或者图片的大小(注意不是目录),就可以使用以下方法:
private void getZipSize(File file) { try { FileInputStream fileIn = new FileInputStream(file); FileChannel channel = fileIn.getChannel(); try { long size = channel.size(); Log.e("getZipSize","getZipSize"+size); } catch (IOException e) { e.printStackTrace(); } } catch (FileNotFoundException e) { e.printStackTrace(); } }
ps:我的博客:http://blog.csdn.NET/shenshizhong
我的简书:http://www.jianshu.com/users/345daf0211ad/latest_articles