Here you can find the source of loadText(File file)
Parameter | Description |
---|---|
file | Description of the Parameter |
Parameter | Description |
---|
public static String loadText(File file) throws java.io.IOException
//package com.java2s; //License from project: Open Source License import java.io.*; import java.util.ArrayList; public class Main { /**/*from www . jav a2 s.c om*/ * Loads text into a string from a file * * @param file Description of the Parameter * @return Description of the Return Value * @throws java.io.IOException Description of the Exception */ public static String loadText(File file) throws java.io.IOException { String ls = System.getProperty("line.separator"); StringBuffer text = new StringBuffer(); BufferedReader in = new BufferedReader(new FileReader(file)); String line = null; boolean hasLine = false; while ((line = in.readLine()) != null) { if (hasLine) { text.append(ls); } text.append(line); hasLine = true; } in.close(); return text.toString(); } /** * Loads text into a string from a file * * @param filename Description of the Parameter * @return Description of the Return Value * @throws java.io.IOException Description of the Exception */ public static String loadText(String filename) throws java.io.IOException { String ls = System.getProperty("line.separator"); StringBuffer text = new StringBuffer(); BufferedReader in = new BufferedReader(new FileReader(filename)); String line = null; boolean hasLine = false; while ((line = in.readLine()) != null) { if (hasLine) { text.append(ls); } text.append(line); hasLine = true; } in.close(); return text.toString(); } /** * Description of the Method * * @param filename Description of the Parameter * @param lines Description of the Parameter * @param ignoreComments Description of the Parameter * @throws java.io.IOException Description of the Exception */ public static void loadText(String filename, ArrayList lines, boolean ignoreComments) throws java.io.IOException { BufferedReader in = new BufferedReader(new FileReader(filename)); String line = null; while ((line = in.readLine()) != null) { if (!ignoreComments || (ignoreComments && !line.startsWith("#") && !"".equals(line.trim()))) { lines.add(line); } } in.close(); } /** * Description of the Method * * @param s Description of Parameter * @return Description of the Returned Value */ public static String toString(String s) { if (s != null) { return (s); } else { return (""); } } }