Java Properties Load from File loadToStringFromFile(String fullFileName)

Here you can find the source of loadToStringFromFile(String fullFileName)

Description

load To String From File

License

LGPL

Declaration

public static String loadToStringFromFile(String fullFileName)
            throws Exception 

Method Source Code

//package com.java2s;
/*//from  ww w.j  a v a2s .c o m
 *   This software is distributed under the terms of the FSF
 *   Gnu Lesser General Public License (see lgpl.txt).
 *
 *   This program is distributed WITHOUT ANY WARRANTY. See the
 *   GNU General Public License for more details.
 */

import java.io.BufferedReader;

import java.io.FileInputStream;

import java.io.InputStreamReader;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Main {
    public static String loadToStringFromFile(String fullFileName)
            throws Exception {
        List<String> lines = loadToStringListFromFile(fullFileName);
        if (lines == null)
            return (String) null;
        String linebreak = System.getProperty("line.separator", "\r\n");
        StringBuilder sb = new StringBuilder();
        Iterator<String> it = lines.iterator();
        while (it.hasNext()) {
            sb.append(it.next()).append(linebreak);
        }
        return sb.toString();
    }

    public static List<String> loadToStringListFromFile(String fullFileName)
            throws Exception {
        List<String> lines = new ArrayList<String>();
        BufferedReader br = null;
        try {
            br = new BufferedReader(new InputStreamReader(
                    new FileInputStream(fullFileName), "utf-8"));
            while (true) {
                String line = br.readLine();
                if (line == null)
                    break;
                lines.add(line);
            }
        } catch (Exception ex) {
            throw ex;
        } finally {
            try {
                if (br != null)
                    br.close();
            } catch (Exception ex) {
            }
        }
        return lines;
    }
}

Related

  1. loadSetting(InputStream in, String key)
  2. loadSettings(String propertiesFileName)
  3. loadStrictly(File file)
  4. loadSystemProperty(String evn, String fileName)
  5. loadTestProperties(String filename)
  6. loadTrimedProperties(String filename)
  7. loadUniversal(InputStream in)
  8. loadUserSettings()
  9. loadWithNormalMode(final String propertyFilePath)