/** * 获取文件大小 * * @param targetFile * @return */ private Long getFileSize(String targetFile) { FileChannel fc = null; long size = 0; try { File f = new File(targetFile); if (f.exists() && f.isFile()) { FileInputStream fis = new FileInputStream(f); fc = fis.getChannel(); size = fc.size(); log.debug(String.valueOf(size)); log.debug(String.valueOf(size / 1024)); } else { log.debug("file doesn't exist or is not a file"); } } catch (FileNotFoundException e) { e.getStackTrace(); } catch (IOException e) { e.getStackTrace(); } finally { if (null != fc) { try { fc.close(); } catch (IOException e) { e.getStackTrace(); } } } return size; }
获取文件大小
最新推荐文章于 2023-02-27 13:48:12 发布