Here you can find the source of readFileFromURL(URL url)
Parameter | Description |
---|---|
url | The url of the file in the bundle. |
public static String readFileFromURL(URL url)
//package com.java2s; /******************************************************************************* * Copyright (c) 2013 Obeo.//from w ww . ja v a2 s.c o m * 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: * Obeo - initial API and implementation *******************************************************************************/ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.URL; public class Main { /** * Reads the content of the file at the given url and returns it. * * @param url * The url of the file in the bundle. * @return The content of the file */ public static String readFileFromURL(URL url) { String result = ""; //$NON-NLS-1$ InputStream openStream = null; InputStreamReader inputStreamReader = null; BufferedReader bufferedReader = null; try { openStream = url.openStream(); } catch (IOException e) { // do nothing, openStream is null } if (openStream != null) { inputStreamReader = new InputStreamReader(openStream); bufferedReader = new BufferedReader(inputStreamReader); StringBuilder stringBuilder = new StringBuilder(); String line = null; try { while ((line = bufferedReader.readLine()) != null) { stringBuilder.append(line); } } catch (IOException e) { e.printStackTrace(); } try { bufferedReader.close(); } catch (IOException e) { e.printStackTrace(); } finally { try { inputStreamReader.close(); } catch (IOException e) { e.printStackTrace(); } finally { try { openStream.close(); } catch (IOException e) { e.printStackTrace(); } } } result = stringBuilder.toString(); } return result; } }