From 2f21ecd6bd431a161702474c08dd0aa32a0daefd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 21 Dec 2023 15:05:56 +0900 Subject: [PATCH] =?UTF-8?q?getList=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nem/lacerta/source/file/FileManager.java | 3 +-- .../source/file/impl/FileManagerImpl.java | 24 ++++++++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java index 56b50791..0fa4062b 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java +++ b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java @@ -11,8 +11,7 @@ public interface FileManager { void changeDir(String dirName); //cd void backDir(); //cd .. void backRootDir(); //cd / - List getDirList(); //ls - List getFileList(); //ls + List getList(); void createDir(); void removeDir(); diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index 43e19657..758737b1 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -2,7 +2,11 @@ package one.nem.lacerta.source.file.impl; import android.graphics.Bitmap; +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.Arrays; import java.util.List; @@ -54,14 +58,18 @@ public class FileManagerImpl implements FileManager { } @Override - public List getDirList() { - // currentDirにあるディレクトリの一覧を返す - return Arrays.asList(currentDir.toFile().list()); - } - - @Override - public List getFileList() { - return null; + public List getList() { + List list = new ArrayList<>(); + try (DirectoryStream stream = Files.newDirectoryStream(currentDir)) { + for (Path entry : stream) { + if (Files.isDirectory(entry)) { + list.add(entry); + } + } + } catch (IOException e) { + e.printStackTrace(); + } + return list; } @Override