读取某个文件夹下的所有文件
(String filepath)
| 212 | * 读取某个文件夹下的所有文件 |
| 213 | */ |
| 214 | public static List<String> readfile(String filepath) throws FileNotFoundException, IOException { |
| 215 | List<String> fileNames = new ArrayList<>(); |
| 216 | File file = new File(filepath); |
| 217 | if (!file.isDirectory()) { |
| 218 | System.out.println("文件"); |
| 219 | System.out.println("path=" + file.getPath()); |
| 220 | System.out.println("absolutepath=" + file.getAbsolutePath()); |
| 221 | System.out.println("name=" + file.getName()); |
| 222 | } else if (file.isDirectory()) { |
| 223 | System.out.println("文件夹????"); |
| 224 | String[] filelist = file.list(); |
| 225 | for (int i = 0; i < filelist.length; i++) { |
| 226 | File readfile = new File(filepath + "\\" + filelist[i]); |
| 227 | if (!readfile.isDirectory()) { |
| 228 | String fileName = readfile.getPath(); |
| 229 | System.out.println("path=" + fileName); |
| 230 | fileNames.add(fileName); |
| 231 | // System.out.println("absolutepath=" |
| 232 | // + readfile.getAbsolutePath()); |
| 233 | // System.out.println("name=" + readfile.getName()); |
| 234 | |
| 235 | } else if (readfile.isDirectory()) { |
| 236 | //文件下面的文件夹 暂时不要 |
| 237 | // readfile(filepath + "\\" + filelist[i]); |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | } |
| 242 | |
| 243 | |
| 244 | return fileNames; |
| 245 | } |
| 246 | |
| 247 | public static void main(String[] args) throws IOException { |
| 248 |