Here you can find the source of loadListFromTextFile(String filename, String defaultitem, String linePrefix, String lineSuffix)
Parameter | Description |
---|---|
filename | String |
defaultitem | String |
linePrefix | String |
lineSuffix | String |
public synchronized static String loadListFromTextFile(String filename, String defaultitem, String linePrefix, String lineSuffix)
//package com.java2s; /**/*from w ww .ja v a 2s .co m*/ * @author David Garratt * * Project Name : Commander4j * * Filename : JUtility.java * * Package Name : com.commander4j.util * * License : GNU General Public License * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program. If not, see * http://www.commander4j.com/website/license.html. * */ import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class Main { /** * Method loadListFromTextFile. * * @param filename * String * @param defaultitem * String * @param linePrefix * String * @param lineSuffix * String * @return String */ public synchronized static String loadListFromTextFile(String filename, String defaultitem, String linePrefix, String lineSuffix) { String result = ""; try { BufferedReader in = new BufferedReader(new FileReader(filename)); String str; if (defaultitem != null) { result = result + linePrefix + defaultitem + lineSuffix; } while ((str = in.readLine()) != null) { if (str.equalsIgnoreCase(defaultitem) == false) { result = result + linePrefix + str + lineSuffix; } } in.close(); } catch (IOException e) { } return result; } }