private boolean downloadFile(String httpUrl, String savePath) { int byteread = 0; try { URL url = new URL(httpUrl); URLConnection conn = url.openConnection(); InputStream inStream = conn.getInputStream(); FileOutputStream fs = new FileOutputStream(savePath); byte[] buffer = new byte[1204]; while ((byteread = inStream.read(buffer)) != -1) { fs.write(buffer, 0, byteread); } System.out.println(savePath+" download finished!"); return true; } catch (MalformedURLException e) { e.printStackTrace(); return false; } catch (IOException e) { e.printStackTrace(); return false; } }
时间: 2024-10-25 15:55:37