File file = new File("newke.jpg");
InputStream in = null;
int length = 0;
in = new BufferedInputStream(new FileInputStream(file));
length = (int)file.length();
file.length () can get a length . Here is the picture , so that access to the file length is correct ? ?
If it is a text file , then the length is the number of characters or bytes it ?
------ Solution ---------------------------------------- ----
The length, in bytes, of the file denoted by this abstract pathname
bytes
------ Solution ---------------------------------- ----------
/**
* 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
*/
public long length() {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkRead(path);
}
return fs.getLength(this);
}
/**
* Return the length in bytes of the file denoted by the given abstract
* pathname, or zero if it does not exist, is a directory, or some other
* I/O error occurs.
*/
public abstract long getLength(File f);
bytes , comments which explains .
没有评论:
发表评论