Here you can find the source of read(String fileName)
public static String[] read(String fileName)
//package com.java2s; //License from project: Apache License import java.io.File; 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[] read(String fileName) { if (fileName == null || fileName.trim().length() <= 0) { return null; }/*from w ww . ja va 2s . c o m*/ ClassLoader classLoader = ClassLoader.getSystemClassLoader(); URL fileUrl = classLoader.getResource(fileName); if (fileUrl == null) { return null; } File file = new File(fileUrl.getFile()); if (file == null || !file.exists()) { return null; } // Read List<String> lines = new ArrayList<String>(); Scanner scanner = null; try { scanner = new Scanner(file); while (scanner.hasNextLine()) { lines.add(scanner.nextLine()); } } catch (IOException e) { e.printStackTrace(); } finally { if (scanner != null) { scanner.close(); } } String[] strs = new String[lines.size()]; lines.toArray(strs); return strs; } }