aspose file tools
The moose likes I/O and Streams and the fly likes how to get Filesize Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Reply Bookmark "how to get Filesize" Watch "how to get Filesize" New topic
Author

how to get Filesize

Angela D'souza
Ranch Hand

Joined: Jan 16, 2002
Posts: 469
Hi,
I have java application. I can get the name of file but how to get the size of that file ?
Thanks,
angela
Sumeet Pandit
Greenhorn

Joined: Mar 09, 2002
Posts: 10
If You want to know the length of the file then use .lenght() method of File class which return long.
ok.


- Sumeet<br />-----------------------------------
Angela D'souza
Ranch Hand

Joined: Jan 16, 2002
Posts: 469
Would you please give me simple example showing how to get the size of file?
Thanks,
Angela
Angela D'souza
Ranch Hand

Joined: Jan 16, 2002
Posts: 469
My Code is here:
File f = new File("Test.txt");
long size = f.length();
This will give me size of the file but if it is 1 KB. If it is more than 1KB, it will give me 0. Why???
Thanks,
Angela
Siva Prasad
Ranch Hand

Joined: Feb 22, 2001
Posts: 104
Hi
If you read the description of the method length(), it clearly says that the return value of length() will be 0L(long value) if it cannot find the specified file name on the disk. So in your example there may not be such file called Test.txt
If you need more clarification, then use exists() method.
cheers
sivaPrasad
 
 
subject: how to get Filesize
 
Threads others viewed
how to get the web link of uploaded file on web server?
contextpath in javscript
file API
How can i show backend table data in CSV format
getting a file name
MyEclipse, The Clear Choice