Here you can find the source of load(File file)
Parameter | Description |
---|---|
file | the file to open |
public static String load(File file)
//package com.java2s; /*/* ww w .ja v a2 s. c o m*/ * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; public class Main { /** * Tries to load the file and return its content. * * @param file the file to open * @return the content, otherwise null */ public static String load(File file) { StringBuffer result; BufferedReader reader; String line; String newLine; result = new StringBuffer(); newLine = System.getProperty("line.separator"); reader = null; try { // add new content reader = new BufferedReader(new FileReader(file)); while ((line = reader.readLine()) != null) { result.append(line); result.append(newLine); } } catch (Exception e) { e.printStackTrace(); result = null; } finally { if (reader != null) { try { reader.close(); } catch (Exception e) { // ignored } } } return ((result != null) ? result.toString() : null); } }