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
posted
0
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
posted
0
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
posted
0
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
posted
0
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