Here you can find the source of readFile(String filename)
Parameter | Description |
---|---|
filename | the path the file to read |
public static String readFile(String filename)
//package com.java2s; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.Scanner; public class Main { /**// w w w . j ava2s. c o m * Reads a certain file of a path. * * @param filename the path the file to read * @return content as the read file */ public static String readFile(String filename) { StringBuilder content = new StringBuilder(); try { String NL = System.getProperty("line.separator"); Scanner scanner = new Scanner(new FileInputStream(filename)); try { while (scanner.hasNextLine()) { content.append(scanner.nextLine() + NL); } } finally { scanner.close(); } } catch (FileNotFoundException e) { e.printStackTrace(); } return content.toString(); } }