Here you can find the source of readFileToSingleString(String path)
public static String readFileToSingleString(String path) throws IOException
//package com.java2s; //License from project: LGPL import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.util.ArrayList; import java.util.List; public class Main { /**/*from w w w.j av a 2s. c om*/ * Get the content of a text file as a single string. */ public static String readFileToSingleString(String path) throws IOException { List<String> lns = new ArrayList<>(); try { lns = Files.readAllLines(new File(path).toPath()); } catch (IOException e) { e.printStackTrace(); } StringBuilder sb = new StringBuilder(); for (String x : lns) sb.append(x).append("\n"); return sb.toString(); } }