views:

176

answers:

3

Hi,

Is there any way in Java (1.6+) to retrieve the partition disk structure? (For example: NTFS, FAT32, HFS+, or EXT3.)

External libraries are permitted.

Thanks,
Gianni

+1  A: 

you could use Runtime.getRuntime().exec() to execute a command like sfdisk and then parse the output.

sfdisk -l /dev/hdc

unfortunately it isn't very platform independent.

Nate Heinrich
Well, I was thinking of writing a class that would execute system dependent commands and extract the information I need from it. But I don't want to reinvent the wheel, you see. If there is a Java library that could do it for me, I don't need to code it myself. Thanks.
Gianni
+1  A: 

Under OS X the output of "mount" includes the file system:

ravn:~ ravn$ mount
/dev/disk0s2 on / (hfs, local, journaled)
devfs on /dev (devfs, local, nobrowse)
map -hosts on /net (autofs, nosuid, automounted, nobrowse)
map auto_home on /home (autofs, automounted, nobrowse)

Here / is of type hfs

Thorbjørn Ravn Andersen
Well, I was thinking of writing a class that would execute system dependent commands and extract the information I need from it. But I don't want to reinvent the wheel, you see. If there is a Java library that could do it for me, I don't need to code it myself. Thanks.
Gianni
Apparently nobody needs it. Why do you?
Thorbjørn Ravn Andersen
I'm writing a program and it needs the disk structure. Like I've said above, I've already started writing my own library.
Gianni
Please be specific. _WHY_ does it need to know the disk structure?
Thorbjørn Ravn Andersen
That has nothing to do with my question. The point is I need to print the disk structure. My Java app doesn't need to know it, the user needs it.
Gianni
Then showing the user the complete output from "mount <location>" on Unix is probably the best, as this ensures that your library assumes as little as possible about the actual output format which varies between systems. Have fun.
Thorbjørn Ravn Andersen
I think so. I'm writing my own library right now. It is already working on unix, mac and linux.
Gianni
+1  A: 

If this doesn't help then - no. You'll need a native library and some OS dependent code for it.

Andreas_D
Thank you for the answer. But I don't like the technique described in that thread.
Gianni