public static List<String> readfile(String filepath) throws FileNotFoundException, IOException {
List<String> list = new ArrayList<>();
try {
File file = new File(filepath);
if (!file.isDirectory()) {
} else if (file.isDirectory()) {
String[] filelist = file.list();
for (int i = 0; i < filelist.length; i++) {
File readfile = new File(filepath + "\\" + filelist[i]);
if (!readfile.isDirectory()) {
list.add(readfile.getPath());
} else if (readfile.isDirectory()) {
readfile(filepath + "\\" + filelist[i]);
}
}
}
} catch (FileNotFoundException e) {
System.out.println("readfile() Exception:" + e.getMessage());
}
return list;
}
public static void main(String[] args) {
String filepath="D:/copy" ;
List<String> list = new ArrayList<>();
try {
list=readfile(filepath);
for (String string : list) {
System.out.println(string);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
List<String> list = new ArrayList<>();
try {
File file = new File(filepath);
if (!file.isDirectory()) {
} else if (file.isDirectory()) {
String[] filelist = file.list();
for (int i = 0; i < filelist.length; i++) {
File readfile = new File(filepath + "\\" + filelist[i]);
if (!readfile.isDirectory()) {
list.add(readfile.getPath());
} else if (readfile.isDirectory()) {
readfile(filepath + "\\" + filelist[i]);
}
}
}
} catch (FileNotFoundException e) {
System.out.println("readfile() Exception:" + e.getMessage());
}
return list;
}
public static void main(String[] args) {
String filepath="D:/copy" ;
List<String> list = new ArrayList<>();
try {
list=readfile(filepath);
for (String string : list) {
System.out.println(string);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}