Here you can find the source of readFile(File file)
Parameter | Description |
---|---|
file | the file to read. |
Parameter | Description |
---|---|
IOException | an exception |
public static String readFile(File file) throws IOException
//package com.java2s; /*/*from w ww . j a va 2s .c om*/ * Stage - Spatial Toolbox And Geoscript Environment * (C) HydroloGIS - www.hydrologis.com * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * (http://www.eclipse.org/legal/epl-v10.html). */ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; public class Main { /** * Read text from a file in one line. * * @param filePath the path to the file to read. * @return the read string. * @throws IOException */ public static String readFile(String filePath) throws IOException { return readFile(new File(filePath)); } /** * Read text from a file in one line. * * @param file the file to read. * @return the read string. * @throws IOException */ public static String readFile(File file) throws IOException { BufferedReader br = null; try { br = new BufferedReader(new FileReader(file)); StringBuilder sb = new StringBuilder(200); String line = null; while ((line = br.readLine()) != null) { sb.append(line); sb.append("\n"); //$NON-NLS-1$ } return sb.toString(); } finally { if (br != null) br.close(); } } }