Java Path File Read nio load(Path p, PrintStream errorStream, String propertyInfo)

Here you can find the source of load(Path p, PrintStream errorStream, String propertyInfo)

Description

load

License

Apache License

Declaration

public static Properties load(Path p, PrintStream errorStream, String propertyInfo) 

Method Source Code


//package com.java2s;
/*/*from  w ww. ja  v a2 s. c o m*/
 * Copyright (c) 2008 Kasper Nielsen.
 *
 * 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.
 */

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.nio.file.Path;

import java.util.Properties;

public class Main {
    public static Properties load(Path p, PrintStream errorStream, String propertyInfo) {
        try {
            FileInputStream fis = new FileInputStream(p.toFile());
            return loadAndClose(fis, errorStream, propertyInfo);
        } catch (FileNotFoundException e) {
            errorStream.println("Could not find property file " + propertyInfo);
            return new Properties();
        }
    }

    public static Properties loadAndClose(InputStream inputStream, PrintStream errorStream, String propertyInfo) {
        try {
            Properties properties = new Properties();
            properties.load(inputStream);
            try {
                inputStream.close();
            } catch (IOException e) {
                errorStream.println(
                        "Could not close property file properly " + propertyInfo + ", failure = " + e.getMessage());
            }
            return properties;
        } catch (IOException e) {
            errorStream.println("Could not load property file " + propertyInfo + ", failure = " + e.getMessage());
        }
        return new Properties();// Failed return a completely empty Properties
    }
}

Related

  1. breadcrumbPath(String urlPrefix, String path, char sep)
  2. checkReadableDirectory(final Path directory)
  3. getReaderForFile(final Path file)
  4. getResourceAsStream(String resourcePath, ClassLoader classLoader, Class clazz, String resourceDesc, Consumer logger)
  5. getTestClassPathURLClassLoader(ClassLoader parent)
  6. loadFile(final Path filePath)
  7. loadFile(final Path p)
  8. loadFile(Path file)
  9. loadFile(String path)