在Android中使用WebView显示网站非常方便。 但我找不到任何方法来获取整个网址(包括图像,CSS)的内容 length.is有可能实现吗?
答案 0 :(得分:0)
String url1 = "";
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.FROYO) {
System.setProperty("http.keepAlive", "false");
}
URL url = new URL(revisedUrl);
URLConnection connection = url.openConnection();
connection.connect();
String result = IOUtils.toString(connection.getInputStream());
int lengthofdownfile=result.length();//content length also same like this
System.out.println(result);
System.out.print("filelength"+lengthofdownfile);
文件sDownlodafile =新文件(mTranscription.getfilename()。getAbsoluteFile(),+ dateFormat.format(date)+“。wav”);
InputStream input = new BufferedInputStream(
url.openStream());
OutputStream output = new FileOutputStream(
sDownlodafile.getAbsoluteFile());
byte data[] = new byte[1024];
int count;
while ((count = input.read(data)) != -1) {
total += count;
publishProgress(""+ (int) ((total * 100) /lengthofdownfile));
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();