Here you can find the source of readFile(String path)
Parameter | Description |
---|---|
path | a parameter |
public static String readFile(String path)
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class Main { /**/* ww w .j av a2 s. c o m*/ * Reads a file and returns the content as a big String. * @param path * @return */ public static String readFile(String path) { StringBuilder buffer = new StringBuilder(); try { BufferedReader reader = new BufferedReader(new FileReader(new File(path))); String line; while ((line = reader.readLine()) != null) buffer.append(line).append('\n'); } catch (FileNotFoundException ex) { System.err.println("File " + path + " was not found..."); System.exit(1); } catch (IOException ex) { System.err.println(ex.getMessage()); System.exit(1); } return buffer.toString(); } }