Google Answers Logo
View Question
 
Q: Java API to find file/disk block size??? ( No Answer,   1 Comment )
Question  
Subject: Java API to find file/disk block size???
Category: Computers > Programming
Asked by: hooji-ga
List Price: $52.82
Posted: 26 Sep 2003 00:56 PDT
Expires: 26 Oct 2003 00:56 PDT
Question ID: 260346
Is it possible to find out the block size of a given disk (or some file
on that disk) from Java 1.4.2, using just the regular Java APIs?
(not using JNI)

How?

Request for Question Clarification by directrix-ga on 27 Sep 2003 19:47 PDT
It is possible to get the size of a specific file, but not to get the
size of a whole disc. Would code that tells you the size of a file be
an acceptable answer?

Clarification of Question by hooji-ga on 27 Sep 2003 20:31 PDT
The block size that I am looking for is the underlying file system block
size.  (Something like 512 bytes, 1024, 4096, etc.)  Each file system has
a minimum block size that represents the smallest unit of data that is
read/written to the disk when data is written to a file.  It is the value
of this block size that I seek.  This value may be different on different
disk volumes on the same system.  The block size is set at the time the
file system is first formatted.

This information is available from the C or C++ language via a call to
the stat(2) system call.  I am looking for the eqivelent functionality
via Java (with no JNI helper code).

The size of the file itself is not required.

Clarification of Question by hooji-ga on 28 Sep 2003 19:42 PDT
Could there be some clever sequence of operations that one might
perform using Java that would reveal the underlying block size somehow?

In other words, can you imagine any clever way to use the existing APIs
to somehow deduce the block size?  Like, make a file with one byte in it,
and somehow via some other method figure out how much space was really
consumed...?  I can't think of a way, but that's why I'm asking  :-)
Answer  
There is no answer at this time.

Comments  
Subject: Re: Java API to find file/disk block size???
From: eadfrith-ga on 28 Sep 2003 12:42 PDT
 
Can't be done I'm afraid. The support for retrieving information on
the underlying file system in Java is quite poor. Basically you're
limited to whatever information the java.io.File class provides, which
is precious little. For example, you can't even query how much free
space is available on the file system.

So, if you really need this information then you're going to have to
use JNI.
Here's a link to an existing freeware implementation than gives you
the information you want, but is limited to Unix platforms:

http://www.xenonsoft.demon.co.uk/products/javaunix/

Sorry to be the bearer of bad news.

Cheers,

Eadfrith

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy