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

LA County APEX

You can use a JavaScript to accomplish that. Check my application

Workspace: ladevapex

User Name: mydevfellow

Password: Pa$$word1

To test the application, follow the steps below:

  • Click Upload New Image button
  • Click Detail button
  • Enter or select the first row objects.
J.col

Hello.

Thanks for the answer and the application infos. I took a look and I learnt a lot of things !

For my issue, I checked your page 7 (detail button) and I didn't understand how it works. I think what I'm doing is very similar to your page 7, but I'm probably missing something.

Here is a part of my application.

pastedImage_0.png

When the user selects a date or a "New" value I want to update my right part with the selected info

pastedImage_1.png

For the moment, I created a PL/SQL process I duplicated in every concerned field.

As this is only a demo application with 4/5 fields, this is not a problem. But at the end, I'll have more than 30 distinct selection fields, and I cannot duplicate my PL/SQL process 30 times ^^

Can you explain me how you would do that please ?

Best regards.

LA County APEX
Answer

All you have to do is to call a JavaScript function to collect value from each item into your display list. Note, this is only to display to the user what being selected. When saving the record, you need to pass the actual value from each item to your process as a parameter.

The following example is the function on page 7 of my application.

function shwVal()

{

  $x('SELVAL').innerHTML = '';

  if ($x('P7_TXT1').value != '')

        $x('SELVAL').innerHTML = $x('P7_TXT1').value;

  var comm = '';

  if ($x('SELVAL').innerHTML)

       comm = ',';

   if ($x('P7_TXT2').value.length == 4)

        $x('SELVAL').innerHTML = $x('SELVAL').innerHTML + comm + $x('P7_TXT2').value;

    if ($x('SELVAL').innerHTML)

       comm = ',';

    $x('SELVAL').innerHTML = $x('SELVAL').innerHTML + comm + apex.item('P7_SEL').getValue();

    if ($f_SelectValue('P7_CHKBX') != '')

        $x('SELVAL').innerHTML = $x('SELVAL').innerHTML + comm + $f_SelectValue('P7_CHKBX');

    if ($x('SELVAL').innerHTML)

       comm = ',';

    if ($f_SelectValue('P7_RADIO') != '')

        $x('SELVAL').innerHTML = $x('SELVAL').innerHTML + comm + $f_SelectValue('P7_RADIO');

}

Marked as Answer by J.col · Sep 27 2020
J.col

Hello !

I'm not familiar with Javascript and its integration into Apex so I didn't look at the good place.

With the search function, I was able to find your JS function and how you call it into your items.

A big thanks !

1 - 4
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,182 views