Here you can find the source of getFileContents(String filename)
public static String getFileContents(String filename)
//package com.java2s; /*/*from www. j a va 2 s . c o m*/ * Copyright IBM Corp. 2011 * * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 * * 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. */ import java.io.IOException; import java.io.InputStream; import java.net.URL; public class Main { public static String getFileContents(String filename) { StringBuffer sb = new StringBuffer(); String p = "xsp/extlib/designer/junit/resources/" + filename; // $NON-NLS-1$ ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); int ch; InputStream in = null; try { URL url = contextClassLoader.getResource(p); in = url.openStream(); } catch (IOException ioe) { ioe.printStackTrace(); } if (null == in) return null; try { while ((ch = in.read()) != -1) sb.append((char) ch); } catch (Exception e) { e.printStackTrace(); } finally { try { in.close(); } catch (Exception e) { } } return sb.toString(); } }