Here you can find the source of readFile(String path)
Parameter | Description |
---|---|
path | the path |
public static String readFile(String path)
//package com.java2s; /*/*from w ww. ja v a 2 s. c o m*/ * FileReaderUtil.java * Copyright (c) 2013, EcoFactor, All Rights Reserved. * * This software is the confidential and proprietary information of EcoFactor * ("Confidential Information"). You shall not disclose such Confidential Information and shall use * it only in accordance with the terms of the license agreement you entered into with * EcoFactor. */ import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class Main { /** * Read file. * @param path the path * @return the string */ public static String readFile(String path) { StringBuilder content = new StringBuilder(); BufferedReader br = null; try { String sCurrentLine; br = new BufferedReader(new FileReader(path)); while ((sCurrentLine = br.readLine()) != null) { content.append(sCurrentLine); } } catch (IOException e) { e.printStackTrace(); } finally { try { if (br != null) br.close(); } catch (IOException ex) { ex.printStackTrace(); } } return content.toString(); } }