Here you can find the source of readClasspathTextFile(String filename)
public static String[] readClasspathTextFile(String filename)
/*/*from w w w . j av a2s. c o m*/ * ************************************************************************************* * Copyright (C) 2008 EsperTech, Inc. All rights reserved. * * http://esper.codehaus.org * * http://www.espertech.com * * ---------------------------------------------------------------------------------- * * The software in this package is published under the terms of the GPL license * * a copy of which has been included with this distribution in the license.txt file. * * ************************************************************************************* */ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main{ public static String[] readClasspathTextFile(String filename) { String filenameCp = findClasspathFile(filename); if (filenameCp == null) { throw new RuntimeException("Failed to find file '" + filename + "' in classpath"); } List<String> lines = new ArrayList<String>(); try { FileInputStream fis = new FileInputStream(filenameCp); Scanner scanner = new Scanner(fis); try { while (scanner.hasNextLine()) { lines.add(scanner.nextLine()); } } finally { scanner.close(); fis.close(); } } catch (IOException ex) { throw new RuntimeException("Failed to read file '" + filename + "': " + ex.getMessage(), ex); } return lines.toArray(new String[lines.size()]); } public static String findClasspathFile(String filename) { URL url = FileUtil.class.getClassLoader().getResource(filename); if (url != null) { return url.getFile(); } return null; } }