Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) throws Exception {
- String destDirectory = "C:\Users\test\text.zip";
- URL url = new URL("http://corpus.byu.edu/wikitext-samples/text.zip");
- downloadFile("http://corpus.byu.edu/wikitext-samples/text.zip", destDirectory);
- }
- public static void downloadFile(String ZIP_FILE_URL, String INPUT_ZIP_FILE) {
- try {
- long startTime = System.currentTimeMillis();
- URL url = new URL(ZIP_FILE_URL);
- url.openConnection();
- InputStream reader = url.openStream();
- FileOutputStream writer = new FileOutputStream(INPUT_ZIP_FILE);
- byte[] buffer = new byte[102400];
- int totalBytesRead = 0;
- int bytesRead = 0;
- System.out.println("Reading ZIP file 20KB blocks at a time.n");
- while ((bytesRead = reader.read(buffer)) > 0) {
- writer.write(buffer, 0, bytesRead);
- buffer = new byte[102400];
- totalBytesRead += bytesRead;
- }
- long endTime = System.currentTimeMillis();
- System.out.println("Done. " + new Integer(totalBytesRead).toString() + " bytes read (" + new Long(endTime - startTime).toString() + " millseconds).n");
- writer.close();
- reader.close();
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
Add Comment
Please, Sign In to add comment