3

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

Chris Gerken
  • 16,221
  • 6
  • 44
  • 59
Gianni
  • 265
  • 5
  • 13

3 Answers3

1

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.

Pang
  • 9,564
  • 146
  • 81
  • 122
Nate Heinrich
  • 1,805
  • 14
  • 14
  • 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 Jan 26 '10 at 14:44
1

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
  • 73,784
  • 33
  • 194
  • 347
  • 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 Jan 26 '10 at 14:45
  • Apparently nobody needs it. Why do you? – Thorbjørn Ravn Andersen Jan 26 '10 at 21:04
  • 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 Jan 27 '10 at 11:14
  • Please be specific. _WHY_ does it need to know the disk structure? – Thorbjørn Ravn Andersen Jan 27 '10 at 11:35
  • 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 Jan 27 '10 at 15:13
  • Then showing the user the complete output from "mount " 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 Jan 27 '10 at 16:21
  • I think so. I'm writing my own library right now. It is already working on unix, mac and linux. – Gianni Jan 28 '10 at 11:49
1

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

Community
  • 1
  • 1
Andreas Dolk
  • 113,398
  • 19
  • 180
  • 268