void downloadToFile(URL url, File file) throws IOException { InputStream in = null; OutputStream out = null; try { in = connector.connect(url); out = new FileOutputStream(file); byte[] buf = new byte[1024]; for(;;) { int bytes = in.read(buf, 0, 1024); if (bytes < 0) break; out.write(buf, 0, bytes); } } finally { try { if (in != null) in.close(); } catch (IOException e) {}; try { if (out != null) in.close(); } catch (IOException e) {}; } }
return cachedFile; try (InputStream data = connector.connect(url)) {
return cachedFile; try (InputStream data = connector.connect(url)) {