Results 1 to 8 of 8
- 10-27-2008, 04:40 AM #1
Member
- Join Date
- Oct 2008
- Posts
- 24
- Rep Power
- 0
How can you get the exact size of a file in bytes.
So, if a file is 308.81MB, how can I get the exact size of the file in bytes? I need to get the exact size of the file because Randomaccessfile's setLength method only excepts long values. That will cause the data to become corrupt in my application. I know how to convert the 308 (multiple by 1048576 = 322961408) part but I don't know what to do with the numbers after the decimal, it comes out as 849346.56 if I multiply it by 1048576. Any ideas on what I can do? I didn't see anything that would help in the API for Randomaccessfile.
- 10-27-2008, 04:46 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
Use,
Java Code:file.length();
- 10-27-2008, 04:56 AM #3
Member
- Join Date
- Oct 2008
- Posts
- 24
- Rep Power
- 0
The file is on a server and I don't want the application to rely on just .getContentLength(). I would like to set it up so that if -1 is returned the user can input the size manually. Thank you for your response.
- 10-27-2008, 04:59 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
So you want to find the file size on client side, where the file is on the server, is it?
- 10-27-2008, 05:05 AM #5
Member
- Join Date
- Oct 2008
- Posts
- 24
- Rep Power
- 0
No, the files will be taken from sites like Megaupload, Deposit Files, Rapidshare, etc... They give the file size as: 90.53 MB for example. So, the user will be able to input that value. I want to convert that value to bytes.
Last edited by J-Live; 10-27-2008 at 05:27 AM.
- 10-27-2008, 08:24 AM #6
Member
- Join Date
- Oct 2008
- Posts
- 24
- Rep Power
- 0
I guess I'll just round the result.
- 10-28-2008, 08:06 AM #7
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
- 10-28-2008, 02:41 PM #8
Similar Threads
-
DES algorithm (Read and Write bytes to file)
By JoaoPe in forum Advanced JavaReplies: 6Last Post: 07-29-2008, 04:46 PM -
[SOLVED] how to replace exact string in java
By pankaj_salwan in forum New To JavaReplies: 22Last Post: 07-08-2008, 10:28 AM -
File size
By eva in forum New To JavaReplies: 2Last Post: 12-19-2007, 10:27 AM -
OutOfMemoryError while creating a new object of file with size more than 150 MB
By Jamie in forum Advanced JavaReplies: 1Last Post: 05-20-2007, 09:52 PM -
How to know the exact word on which the mouse is, in a JTextArea
By JavaBean in forum AWT / SwingReplies: 1Last Post: 05-19-2007, 01:03 PM
Bookmarks