Java 获取文件大小
2017-08-29 14:29
393 查看
// 文件大小 public static void main(String[] args) { File f = new File("D:\\CentOS-6.5-x86_64-bin-DVD1.iso"); if (f.exists() && f.isFile()) { logger.info(f.length()); } else { logger.info("file doesn't exist or is not a file"); } } /* * 针对流式方法读取大文件大小也不是不可行, 只是不能再使用传统的java.io.*下的包了, * 这里要用到java.nio.*下的新工具——FileChannel */ public static void main(String[] args) { FileChannel fc= null; try { File f= new File("D:\\CentOS-6.5-x86_64-bin-DVD1.iso"); if (f.exists() && f.isFile()){ FileInputStream fis= new FileInputStream(f); fc= fis.getChannel(); logger.info(fc.size()); }else{ logger.info("file doesn't exist or is not a file"); } } catch (FileNotFoundException e) { logger.error(e); } catch (IOException e) { logger.error(e); } finally { if (null!=fc)){ try{ fc.close(); }catch(IOException e){ logger.error(e); } } } }
相关文章推荐
- java 获取文件夹大小,文件大小,文件个数
- java 获取文件夹大小,文件大小,文件个数
- Java获取文件大小,文件夹内文件个数的工具类
- java 获取网络servelt 返回下载文件大小
- java 获取文件夹大小,文件大小,文件个数
- Java获取文件大小
- javaIo获取文件大小
- Java中获取文件大小的详解及实例代码
- Java中获取文件大小的正确方法
- java 获取文件夹大小,文件大小,文件个数
- 遇到问题---java获取网络文件大小失败getContentLength()为-1 完整解决方法
- 获取文件大小的java程序
- Java中获取文件大小的正确方法
- java开发中如何获取远程文件的大小
- java 获取文件夹大小,文件大小,文件个数
- Java中获取文件大小的正确方法
- 使用java读取txt里边的文件内容并获取大小(M).txt
- java file对象获取文件大小
- java 获取文件夹大小、文件大小、文件个数
- java获取文件夹和文件大小