Java Path File Name nio subDirectoryNames(final Path dir)

Here you can find the source of subDirectoryNames(final Path dir)

Description

Gets the list of subdirectory names in the given directory path.

License

Open Source License

Parameter

Parameter Description
dir path to the directory

Exception

Parameter Description
IOException if opening the directory fails

Return

list of subdirectory names

Declaration

private static List<String> subDirectoryNames(final Path dir) throws IOException 

Method Source Code

//package com.java2s;
/**//from   ww  w.  ja  v  a 2 s. c o m
 * The MIT License
 * Copyright (c) 2015 Estonian Information System Authority (RIA), Population Register Centre (VRK)
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**
     * Gets the list of subdirectory names in the given directory path.
     * @param dir path to the directory
     * @return list of subdirectory names
     * @throws IOException if opening the directory fails
     */
    private static List<String> subDirectoryNames(final Path dir) throws IOException {
        List<String> subdirs = new ArrayList<>();
        try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, Files::isDirectory)) {
            for (Path subDir : stream) {
                String conf = subDir.getFileName().toString();
                subdirs.add(conf);
            }
            return subdirs;
        }
    }
}

Related

  1. saveFileFromByteArray(String filename, String pathDirectory, byte[] data)
  2. saveNamesToFile(Map namesMap, Path namesFile)
  3. saveToFile(String content, String directoryPath, String filename)
  4. shortenFileName(Path file, List dirs)
  5. storeFile(String fileName, InputStream inputStream, Path targetPath)
  6. toClassName(String path)
  7. toResourcePath(String fileName)
  8. unzipFile(String fileName, String targetPath)
  9. uploadFileToServer(InputStream input, String filename, String usercode, String basePath)