Java Android Webview应用未成功下载
我的Android应用程序具有访问我的网站的网络视图。我在服务器上注意到,当应用程序下载文件时,使用的带宽比其他设备或浏览器下载的带宽要小 在onDownloadStart方法中,我调用AsyncTask类:Java Android Webview应用未成功下载,java,android,webview,Java,Android,Webview,我的Android应用程序具有访问我的网站的网络视图。我在服务器上注意到,当应用程序下载文件时,使用的带宽比其他设备或浏览器下载的带宽要小 在onDownloadStart方法中,我调用AsyncTask类: protected String doInBackground(String... sUrl) { try { URL url = new URL(sUrl[0]); //Getting directory to store the file
protected String doInBackground(String... sUrl) {
try {
URL url = new URL(sUrl[0]);
//Getting directory to store the file
//Connection handler
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setDoOutput(true);
connection.connect();
//Obtaining filename
File outputFile = new File(directory, filename);
InputStream input = new BufferedInputStream(connection.getInputStream());
OutputStream output = new FileOutputStream(outputFile);
byte buffer[] = new byte[1024];
int bufferLength = 0;
int total = 0;
while ((bufferLength=input.read(buffer))!=-1) {
total += bufferLength;
output.write(buffer, 0, bufferLength);
}
connection.disconnect();
output.flush();
output.close();
input.close();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
下载的文件是空的,尽管它们的文件名和格式是正确的,并且我从服务器收到HTTP 200消息;执行也不会进入while循环。我试图改变缓冲区大小,但问题没有解决