我有一个指向服务器存储库位置的链接列表,Links代表一些资源,包括图像,xml,txt,csv(每个不同大小)的文件,但是我面临的问题是,当我下载文件所有下载的文件具有相同的文件大小。从URL下载资源java
List<String> Links;//list of links dynamically populated
for(String link:Links)
{
int i=link.lastIndexOf("/");
String temp=link.substring(0, i);
String contentname = temp.substring(temp.lastIndexOf("/")+1);
String filePath = tempFolderPath + "\\" + contentname;
URL url = new URL(link);
URLConnection connection = url.openConnection();
InputStream is = new DataInputStream(connection.getInputStream());
FileOutputStream fos = null;
try {
fos = new FileOutputStream(new File(filePath));
int inByte;
while((inByte = is.read()) != -1)
fos.write(inByte);
is.close();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
finally
{
try {
is.close();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
其中链接直接访问的源泉“//localhost:8090/documents/11234/13935/abc.txt”
下载的文件是什么?实际内容?别的东西? – jtahlborn
如果我打开下载的图像类型jpg,png它不会打开和其他文件包含数据,但不完整的数据。 – Ali
你是否收到异常? – jtahlborn