当前位置: 技术问答>java相关
java里怎么知道一个file的大小?
来源: 互联网 发布时间:2015-10-03
本文导语: java里怎么知道一个file的大小?有什么方法吗? | length public long length() Returns the length of the file denoted by this abstract pathname. The return value is unspecified if this pathname denotes a directory...
java里怎么知道一个file的大小?有什么方法吗?
|
length
public long length()
Returns the length of the file denoted by this abstract pathname. The return value is unspecified if this pathname denotes a directory.
Returns:
The length, in bytes, of the file denoted by this abstract pathname, or 0L if the file does not exist
Throws:
SecurityException - If a security manager exists and its SecurityManager.checkRead(java.lang.String) method denies read access to the file
eg:File file = new File(filepathname);
long len = file.length()
public long length()
Returns the length of the file denoted by this abstract pathname. The return value is unspecified if this pathname denotes a directory.
Returns:
The length, in bytes, of the file denoted by this abstract pathname, or 0L if the file does not exist
Throws:
SecurityException - If a security manager exists and its SecurityManager.checkRead(java.lang.String) method denies read access to the file
eg:File file = new File(filepathname);
long len = file.length()
|
String homepagepath="D:/java/temp.txt";
File file1=new File(homepagepath);
System.out.println(file1.length());
-----------
Class File -length
public long length()
Returns the length of the file denoted by this abstract pathname.
Returns:
The length, in bytes, of the file denoted by this abstract pathname, or 0L if the file does not exist
Throws:
SecurityException - If a security manager exists and its SecurityManager.checkRead(java.io.FileDescriptor) method denies read access to the file
File file1=new File(homepagepath);
System.out.println(file1.length());
-----------
Class File -length
public long length()
Returns the length of the file denoted by this abstract pathname.
Returns:
The length, in bytes, of the file denoted by this abstract pathname, or 0L if the file does not exist
Throws:
SecurityException - If a security manager exists and its SecurityManager.checkRead(java.io.FileDescriptor) method denies read access to the file
|
File file = new File("c:/test.txt");
System.out.println(file.length());
System.out.println(file.length());
|
File file = new File(yourFileName);
long length = file.length();
long length = file.length();
|
The length, in bytes, of the file denoted by this abstract pathname, or 0L if the file does not exist
当前路径名所指向的文件的字节数 或者为0改文件不存在
当前路径名所指向的文件的字节数 或者为0改文件不存在