java下载整个文件夹_Java下载目录中的所有文件和文件夹

你需要下载页面,这是目录列表,解析它,然后下载链接在页面中的inidiviudal文件…

你可以做点什么……

URL url = new URL("http:www.futureretrogaming.tk/gamefiles/ProfessorPhys");

InputStream is = null;

try {

is = url.openStream();

byte[] buffer = new byte[1024];

int bytesRead = -1;

StringBuilder page = new StringBuilder(1024);

while ((bytesRead = is.read(buffer)) != -1) {

page.append(new String(buffer, 0, bytesRead));

}

// Spend the rest of your life using String methods

// to parse the result...

} catch (IOException ex) {

ex.printStackTrace();

} finally {

try {

is.close();

} catch (Exception e) {

}

}

或者,您可以下载Jsoup并使用它来完成所有艰苦工作……

try {

Document doc = Jsoup.connect("http:www.futureretrogaming.tk/gamefiles/ProfessorPhys").get();

Elements links = doc.getElementsByTag("a");

for (Element link : links) {

System.out.println(link.attr("href") + " - " + link.text());

}

} catch (IOException ex) {

ex.printStackTrace();

}

哪个输出……

?C=N;O=D - Name

?C=M;O=A - Last modified

?C=S;O=A - Size

?C=D;O=A - Description

/gamefiles/ - Parent Directory

Assembly-CSharp-Editor-firstpass-vs.csproj - Assembly-CSharp-Edit..>

Assembly-CSharp-Editor-firstpass.csproj - Assembly-CSharp-Edit..>

Assembly-CSharp-Editor-firstpass.pidb - Assembly-CSharp-Edit..>

Assembly-CSharp-firstpass-vs.csproj - Assembly-CSharp-firs..>

Assembly-CSharp-firstpass.csproj - Assembly-CSharp-firs..>

Assembly-CSharp-firstpass.pidb - Assembly-CSharp-firs..>

Assembly-CSharp-vs.csproj - Assembly-CSharp-vs.c..>

Assembly-CSharp.csproj - Assembly-CSharp.csproj

Assembly-CSharp.pidb - Assembly-CSharp.pidb

Assembly-UnityScript-Editor-firstpass-vs.unityproj - Assembly-UnityScript..>

Assembly-UnityScript-Editor-firstpass.pidb - Assembly-UnityScript..>

Assembly-UnityScript-Editor-firstpass.unityproj - Assembly-UnityScript..>

Assembly-UnityScript-firstpass-vs.unityproj - Assembly-UnityScript..>

Assembly-UnityScript-firstpass.pidb - Assembly-UnityScript..>

Assembly-UnityScript-firstpass.unityproj - Assembly-UnityScript..>

Assembly-UnityScript-vs.unityproj - Assembly-UnityScript..>

Assembly-UnityScript.pidb - Assembly-UnityScript..>

Assembly-UnityScript.unityproj - Assembly-UnityScript..>

Assets/ - Assets/

Library/ - Library/

Professor%20Phys-csharp.sln - Professor Phys-cshar..>

Professor%20Phys.exe - Professor Phys.exe

Professor%20Phys.sln - Professor Phys.sln

Professor%20Phys.userprefs - Professor Phys.userp..>

Professor%20Phys_Data/ - Professor Phys_Data/

Script.doc - Script.doc

~$Script.doc - ~$Script.doc

~WRL0392.tmp - ~WRL0392.tmp

~WRL1966.tmp - ~WRL1966.tmp

然后,您需要为每个文件构建一个新URL,并按照您已经完成的方式进行读取…

例如,Assembly-CSharp-Edit的href ..>是Assembly-CSharp-Editor-firstpass-vs.csproj,它出现在一个相对链接中,所以你需要在http://www.futureretrogaming.tk/gamefiles/ProfessorPhys前面加上这个来创建一个新的http:// URL www.futureretrogaming.tk/gamefiles/ProfessorPhys/Assembly-CSharp-Editor-firstpass-vs.csproj

您需要为要抓取的每个元素执行此操作

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值