Here you can find the source of downloadFile(final String url)
public static byte[] downloadFile(final String url) throws Exception
//package com.java2s; /**// w ww.j a v a 2 s . c o m * * Licensed under the GNU General Public License (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.gnu.org/licenses/gpl.txt * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * * @author Vadim Kisen * * copyright 2010 by uTest */ import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.net.URL; public class Main { public static byte[] downloadFile(final String url) throws Exception { final URL fileUrl = new URL(url); final InputStream in = fileUrl.openStream(); final ByteArrayOutputStream buf = new ByteArrayOutputStream(); final byte[] readBuf = new byte[1024]; int read = in.read(readBuf); while (read > 0) { buf.write(readBuf, 0, read); read = in.read(readBuf); } return buf.toByteArray(); } }