Package ca.pgon.st.light6

Source Code of ca.pgon.st.light6.FileTools

/*
    Small Tools - Some basic libraries for developing and testing http://www.pgon.ca/st
    Copyright (C) 2013-2014 Small Tools (info@pgon.ca)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/
package ca.pgon.st.light6;

import java.io.File;
import java.io.FileInputStream;

import ca.pgon.st.light6.exception.StLightException;

/**
* Some common methods to manage resources files.
*
* @author Simon Levesque
*
*/
public final class FileTools {

    /**
     * Load a file as a String.
     *
     * @param file
     *            the file to open
     * @return the string
     */
    public static String getFileAsString(File file) {
        try {
            return StreamsUtils.consumeAsString(new FileInputStream(file));
        } catch (Exception e) {
            throw new StLightException(e);
        }
    }

    /**
     * Load a file as a String.
     *
     * @param fileName
     *            the file path to open
     * @return the string
     */
    public static String getFileAsString(String fileName) {
        try {
            return StreamsUtils.consumeAsString(new FileInputStream(fileName));
        } catch (Exception e) {
            throw new StLightException(e);
        }
    }
}
TOP

Related Classes of ca.pgon.st.light6.FileTools

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.