Here you can find the source of readFile(String filePath)
Parameter | Description |
---|---|
filePath | the file path |
public static String readFile(String filePath)
//package com.java2s; /*//from w w w. j ava 2 s . c o m * FileUtil.java * Copyright (c) 2014, CODEROAD, All Rights Reserved. * * This software is the confidential and proprietary information of CODEROAD * ("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 * CODEROAD. */ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; public class Main { /** * Read file. * * @param filePath the file path * @return the string */ public static String readFile(String filePath) { StringBuffer stringBuffer = null; try { FileReader fileReader = new FileReader(new File(filePath)); BufferedReader bufferedReader = new BufferedReader(fileReader); stringBuffer = new StringBuffer(); String line; while ((line = bufferedReader.readLine()) != null) { stringBuffer.append(line); stringBuffer.append("\n"); } fileReader.close(); return stringBuffer.toString(); } catch (IOException e) { e.printStackTrace(); } return stringBuffer.toString(); } }