获取文件的总大小(以字节为单位)
可能重复:
Java高效地获取文件大小
我有位于E://file.txt文件称为文件名。 
 FileInputStream fileinputstream =new FileInputStream(filename); 
 我想要做的是计算这个文件的总bytes数? 我怎样才能做到这一点? 
 您可以在File上使用length()方法,返回大小(以字节为单位)。 
 您不需要FileInputStream来计算文件大小, new File(path_to_file).length()就足够了。 或者,如果你坚持,使用fileinputstream.getChannel().size() 。 
 你可以用Files.size(new File(filename).toPath())来做到这一点。 
 public static void main(String[] args) { try { File file = new File("test.txt"); System.out.println(file.length()); } catch (Exception e) { } }