Last active
December 17, 2015 03:59
-
-
Save kazua/5547094 to your computer and use it in GitHub Desktop.
ファイル検索
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //write kazua | |
| import java.io.File; | |
| import java.util.*; | |
| public class fileSearch { | |
| private List<String> getFiles(String path) { | |
| List<String> pl = new ArrayList<String>(); | |
| File file = new File(path); | |
| if (!file.isDirectory()) file = file.getParentFile(); | |
| for (File fc : file.listFiles()) { | |
| if (fc.isDirectory()) pl.addAll(getFiles(fc.getPath())); | |
| else pl.add(fc.getPath()); | |
| } | |
| return pl; | |
| } | |
| public static void main(String[] args) { | |
| try { | |
| List<String> rl = new ArrayList<String>(); | |
| fileSearch fs = new fileSearch(); | |
| rl = fs.getFiles("D:/写真"); | |
| for (int i = 0; i < rl.size(); i++) System.out.println(rl.get(i)); | |
| } catch (Exception e) { | |
| System.out.println(e.toString()); | |
| if (e.getCause() != null) | |
| for (StackTraceElement ste : e.getCause().getStackTrace()) | |
| System.out.println(ste.toString()); | |
| else | |
| for (StackTraceElement ste : e.getStackTrace()) | |
| System.out.println(ste.toString()); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment