S
S
SoloCheater2018-08-11 08:05:46
Java
SoloCheater, 2018-08-11 08:05:46

How to get from an array of disks File.listRoots() the one you need in Java?

Hello. I am writing my program in Java. There is code below:

package com.technicalkeeda;
 
import java.io.File;
 
public class App {
 
    public static void main(String[] args) {
 
        File[] roots = File.listRoots();
 
        System.out.println("List of available filesystem roots:- ");
 
        for (File root: roots) {
 
            System.out.println(root);
        }
 
    }
}

This code lists all possible drives from the array File[] roots = File.listRoots();
Example:
List of available filesystem roots:- 
 
C:\
D:\
E:\

And I need to filter this list and display a specific one by the filter. How to do it?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question