Java URL to File Name getFileFromUrl(URL url)

Here you can find the source of getFileFromUrl(URL url)

Description

get File From Url

License

Open Source License

Declaration

private static File getFileFromUrl(URL url) throws IOException 

Method Source Code

//package com.java2s;
/*/*  w w w.ja v  a2  s  . c om*/
 * Copyright 2014 Qunar.com All right reserved. This software is the
 * confidential and proprietary information of Qunar.com ("Confidential
 * Information"). You shall not disclose such Confidential Information and shall
 * use it only in accordance with the terms of the license agreement you entered
 * into with Qunar.com.
 */

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

public class Main {

    private static File getFileFromUrl(URL url) throws IOException {
        File tmpImage = File.createTempFile("tesseract-ocr-download", null);
        InputStream in = url.openConnection().getInputStream();
        FileOutputStream fos = new FileOutputStream(tmpImage);
        byte[] buf = new byte[1024];
        int len = 0;
        while ((len = in.read(buf)) != -1) {
            fos.write(buf, 0, len);
        }
        fos.flush();
        fos.close();
        return tmpImage;
    }
}

Related

  1. getFileForURL(String url)
  2. getFileForUrl(URL url)
  3. getFileFrom(final URL url)
  4. getFileFromUrl(String url, File base)
  5. getFileFromUrl(String urlPath)
  6. getFileFromURL(URL url)
  7. getFileFromURL(URL url)
  8. getFileFromURL(URL urlToDecode)
  9. getFileName(final CharSequence url)