0
我有一個示例代碼來從網絡和它的一個swing應用程序下載一些數據(pdf,gif和mp3)。它在Windows 7中完美工作,但不能在Windows XP中工作。擺動下載不工作在Windows XP中
我的代碼是
public static Float downloadFile(String targetUrl,File filePath)
{
try
{
Integer count=0;
URL url = new URL(targetUrl);
HttpURLConnection connection=(HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setDoOutput(true);
connection.setConnectTimeout(10000);
connection.connect();
int lenghtOfFile = connection.getContentLength();
Thread.sleep(100);
InputStream input = new BufferedInputStream(url.openStream());
Thread.sleep(100);
OutputStream output = new FileOutputStream(filePath);
byte data[] = new byte[input.available()];
long total = 0;
while ((count = input.read(data)) != -1)
{
total += count;
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
}
catch (Exception e)
{
e.printStackTrace();
}
return 2.5f;
}
}
while循環通過代碼設置爲0
這兩個系統是否安裝了相同的JRE?什麼是Thread.sleep? – Adrian 2013-03-01 07:35:29