Java BufferedReader Read loadListFromTextFile(String filename, String defaultitem, String linePrefix, String lineSuffix)

Here you can find the source of loadListFromTextFile(String filename, String defaultitem, String linePrefix, String lineSuffix)

Description

Method loadListFromTextFile.

License

Open Source License

Parameter

Parameter Description
filename String
defaultitem String
linePrefix String
lineSuffix String

Return

String

Declaration

public synchronized static String loadListFromTextFile(String filename, String defaultitem, String linePrefix,
        String lineSuffix) 

Method Source Code

//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;
    }
}

Related

  1. loadLines(String file)
  2. loadLines(String fileName)
  3. loadList(File f, String enc)
  4. loadList(final File file)
  5. loadList(String listName)
  6. loadLongArray(BufferedReader in)
  7. loadMetadata(File file)
  8. loadMetaFile(File metaFile)
  9. loadMimeTypes(Reader in, Map extMap, Map mimeMap)