Here you can find the source of readFile(URL file)
public static String readFile(URL file)
//package com.java2s; /******************************************************************************* * Copyright (c) 2004, 2005 Sybase, Inc. and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*from w w w . j a va2 s. co m*/ * Sybase, Inc. - initial API and implementation *******************************************************************************/ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; public class Main { public final static int DEFAULT_FILE_SIZE = 15 * 1024; public static String readFile(URL file) { BufferedReader in = null; try { in = new BufferedReader(new InputStreamReader(file.openStream()), DEFAULT_FILE_SIZE); StringBuffer buffer = new StringBuffer(DEFAULT_FILE_SIZE); char[] readBuffer = new char[2048]; int n = in.read(readBuffer); while (n > 0) { buffer.append(readBuffer, 0, n); n = in.read(readBuffer); } return buffer.toString(); } catch (IOException e) { e.printStackTrace(); } finally { if (in != null) { try { in.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return ""; } }