Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Java - Read Linux Filesystem Space

frank.anelliaNov 27 2017 — edited Nov 28 2017

Hello,

I'm new to Java programming and I'm working on a file to read through the Linux filesystem.  Currently, I wrote a very simple program where I need to assign a drive name to a variable in order to retrieve disk space such as:

File file = new File("/u01");

This only allows me to report on the '/u01' filesystem.  However, the server contains multiple filesystems such as /backups, /tmp, etc.  I'd also like to report on these as well.  The following works on my Windows machine but not Linux:

import java.io.File;

public class diskSpaceDetail

{

    public static void main(String[] args)

    {

        File[] roots = File.listRoots();

       

        for(int i = 0; i < roots.length; i++)

        {

            System.out.println("drive:" + roots[i]);

          

        }

The above code returns nothing for Linux.  Here is the full script that works on Linux:

import java.io.File;

public class diskSpaceDetail

{

    public static void main(String[] args)

    {

        File file = new File("/u01");

        long totalSpace = file.getTotalSpace(); //total disk space in bytes.

        long usableSpace = file.getUsableSpace(); ///unallocated / free disk space in bytes.

        long freeSpace = file.getFreeSpace(); //unallocated / free disk space in bytes.

        double totalSpaceGB = totalSpace / 1024 / 1024 / 1024;

        double usableSpaceGB = usableSpace / 1024 / 1024 / 1024;

        double freeSpaceGB = freeSpace / 1024 / 1024 / 1024;

        String heading1 = "Filesystem";

        String heading2 = "Total Size (GB)";

        String heading3 = "Usable Space (GB)";

        String heading4 = "Free Space (GB)";

        String divider = "--------------------------------------------------------------";

        System.out.println("");

        System.out.printf("%-20s %20s %20s %20s %n", heading1,heading2,heading3,heading4);

        System.out.println(divider);

        System.out.printf("%-20s %20s %20s %20s %n",file,totalSpaceGB,usableSpaceGB,freeSpaceGB);

    }

}

Is there a way I can iterate through all of the Linux filesystems without entering a value such as "/u01"?

Thanks,

Frank

Comments

bkmcdaniel
Answer
Marked as Answer by 4187794 · Sep 27 2020
InoL

See yesterday's topic (which means if you search before you ask, you will have an answer much quicker):

Oracle Apex Migration(Access to Apex 19.2)

4187794

bkmcdaniel: Thank you for the link!

InoL: I have done a lot of searching. I apologize for not finding that discussion and posting a new thread.

I saw a question on there that I have. Can we stand up an older apex instance to convert applications then migrate those into 19c  - does anyone know how feasible/reliable of an approach this may be?

InoL
Can we stand up an older apex instance to convert applications then migrate those into 19c  -

You can.

However, there is a reason Oracle stopped support: the result was very poor. There is just no way to convert the code to PL/SQL and Javascript automatically. In the end you have to do everything manually anyway.

4187794

Thanks ya, appreciate it.

edit: Even though you have made me sad.

1 - 5
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Dec 26 2017
Added on Nov 27 2017
1 comment
3,132 views