Here you can find the source of readFile(String file)
Parameter | Description |
---|---|
file | : It is the full path to the file |
public static String readFile(String file)
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class Main { /**/*from w ww . j a v a 2s .c o m*/ * * @param file * : It is the full path to the file * * @return String with the content of the file */ public static String readFile(String file) { BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(file)); } catch (FileNotFoundException e) { e.printStackTrace(); throw new RuntimeException("Can't find the file", e); } String line = null; StringBuilder stringBuilder = new StringBuilder(); String ls = System.getProperty("line.separator"); try { while ((line = reader.readLine()) != null) { stringBuilder.append(line); stringBuilder.append(ls); } return stringBuilder.toString(); } catch (IOException e) { e.printStackTrace(); return null; } finally { reader = null; } } }