Here you can find the source of getFileFromUrl(URL url)
private static File getFileFromUrl(URL url) throws IOException
//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; } }