File file = new File("newke.jpg");
InputStream in = null;
int length = 0;
in = new BufferedInputStream(new FileInputStream(file));
length = (int)file.length();
file.length() 可以得到一个长度。这里是图片,这样获取是文件长度是否正确??
如果是文本文件,那么这个长度是字符数,还是字节数呢?
------解决方案--------------------
The length, in bytes, of the file denoted by this abstract pathname
字节
------解决方案--------------------
/**
* Returns the length of the file denoted by this abstract pathname.
* The return value is unspecified if this pathname denotes a directory.
*
* @return The length, in bytes, of the file denoted by this abstract
* pathname, or <code>0L</code> if the file does not exist. Some
* operating systems may return <code>0L</code> for pathnames
* denoting system-dependent entities such as devices or pipes.
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkRead(java.lang.String)}</code>
* method denies read access to the file