Results 1 to 3 of 3

Thread: Getting drive info in java

  1. #1
    Join Date
    Jul 2012
    Beans
    8

    Getting drive info in java

    Okay, I am working on a security suite, but I need to list all drives and partitions on said drives. The base language is Java, but C/C++ libraries can be loaded.

    This is what I have now:
    PHP Code:
    import java.io.File;
    for(
    File f File.getRoots()) {
        
    System.out.println("Root: " f.getName());

    But it only outputs:
    Code:
    Root: /
    However, I have my home folder on a separate partition, so when I run this:
    PHP Code:
    for(String s : new String[] {"/""/home"}) {
        
    System.out.println("Size of " " is " + (new File(s).getTotalSpace() / 1024 1024 1024) + " GB");

    I get this:
    Code:
    Size of / is 96 GB
    Size of /home is 355 GB
    Which proves I have 2 partitions

    I need the application to detect all partitions so it can scan them. Any help would be appreciated.

    ALSO:
    File.listRoots() does not list USB drives and such, which I will also need, if you have any advice on that I would be grateful.

    THANKS!
    Last edited by andrewkrieg; October 7th, 2013 at 01:04 PM.

  2. #2
    Join Date
    Aug 2011
    Location
    47°9′S 126°43W
    Beans
    2,160
    Distro
    Kubuntu 14.04 Trusty Tahr

    Re: Getting drive info in java

    As its name implies, listsRoots() lists roots and not filesystems. If you RTFM:

    A particular Java platform may support zero or more hierarchically-organized file systems. Each file system has a root directory from which all other files in that file system can be reached. Windows platforms, for example, have a root directory for each active drive; UNIX platforms have a single root directory, namely "/".

    If you security suite has any value it has to be very system-dependent... For Linux the mounted file systems can be found in /etc/mtab. However if you scan everything under "/" you will scan all the filesystems...
    Last edited by ofnuts; October 5th, 2013 at 10:21 PM.
    Warning: unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.

  3. #3
    Join Date
    Jul 2012
    Beans
    8

    Re: Getting drive info in java

    Thank you! very much.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •