?
Solved

Getting size of a file

Posted on 2005-05-05
2
Medium Priority
?
272 Views
Last Modified: 2010-03-31
Is there a way to get the size of a file object without actually reading the entire file?

If not, will reading the file and checking the length() of it provide me with an accurate size? How big is each char?

aString.length() * 2 //if chars are 16-bit?

or is it better to use:
 
byte[] array = aString.getBytes()
int sizeInBits = array.length

Thanks
0
Comment
Question by:kristofer
2 Comments
 
LVL 15

Accepted Solution

by:
aozarov earned 200 total points
ID: 13936877
new File(xxxx).length() return the size without reading it.
0
 
LVL 1

Expert Comment

by:junkiesuperstar
ID: 13937591
aozarov is right I believe. From your question, I'm guessing there's some confusion on Java's data types. To summarise :

Java's String / Char are Unicode encoded - 16 bits / character

Text in common text files are either ASCII / ISO-8859 encoded - 8 bits / character

Therefore size of file is very dependant on the encoding use for the text data.
The text in file can be encoded in either way(most commonly). Typically most txt files are ASCII / ISO-8895 encoded.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Suggested Courses
Course of the Month13 days, 22 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question