Here you can find the source of readAllText(File file)
Parameter | Description |
---|---|
file | the file to read |
public static String readAllText(File file)
//package com.java2s; // under the terms of the GNU Lesser General Public License as published by import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.util.Vector; public class Main { /**/*from w w w . j a v a 2 s.c om*/ * Read the given file and return its contents as string * * @param file * the file to read * @return its contents as string */ public static String readAllText(File file) { if (file == null || !file.exists()) return null; BufferedReader reader; StringBuilder builder = new StringBuilder(); try { reader = new BufferedReader(new FileReader(file)); String line; while ((line = reader.readLine()) != null) builder.append(line + "\n"); reader.close(); } catch (Exception e) { } return builder.toString(); } /** * Returns the items of the given vector as comma separated list * * @param items * the vector to flatten * @return string of comma separated items */ public static String toString(Vector<String> items) { if (items == null || items.size() == 0) return ""; StringBuilder builder = new StringBuilder(); for (int i = 0; i < items.size(); i++) { builder.append(items.get(i)); if (i + 1 < items.size()) builder.append(", "); } return builder.toString(); } }