网络下载

//连接网络下载资源
			URL url = new URL(filepath);
			URLConnection conn = url.openConnection();
			conn.setConnectTimeout(10000);
			conn.connect();
InputStream is = conn.getInputStream();
			totalsize = conn.getContentLength();
			//filetype = conn.getContentType();
			byte[] b;
			BufferedInputStream bis = new BufferedInputStream(is);
			FileOutputStream output = new FileOutputStream(f);
			count = 0;
			while (count<totalsize) {
				b= new byte[bis.available()];//接收有效长度的数据
				bis.read(b);
				count += b.length;
				output.write(b);
				output.flush();
			}
			is.close();
			bis.close();
			output.close();

 

你可能感兴趣的:(F#)