天天看點

java 抓取伺服器檔案夾_java 怎麼通過url擷取遠端伺服器上某個檔案夾下的所有檔案名...

public static boolean readfile(String filepath) throws FileNotFoundException, IOException {

try {

File file = new File(filepath);

if (!file.isDirectory()) {

System.out.println("檔案");

System.out.println("path=" + file.getPath());

System.out.println("absolutepath=" + file.getAbsolutePath());

System.out.println("name=" + file.getName());

} else if (file.isDirectory()) {

System.out.println("檔案夾");

String[] filelist = file.list();

for (int i = 0; i < filelist.length; i++) {

File readfile = new File(filepath + "\\" + filelist[i]);

if (!readfile.isDirectory()) {

System.out.println("path=" + readfile.getPath());

System.out.println("absolutepath="

+ readfile.getAbsolutePath());

System.out.println("name=" + readfile.getName());

} else if (readfile.isDirectory()) {

readfile(filepath + "\\" + filelist[i]);

}

}

}

} catch (FileNotFoundException e) {

System.out.println("readfile() Exception:" + e.getMessage());

}

return true;

}