Java FileInputStream Read readFile(String fileName)

Here you can find the source of readFile(String fileName)

Description

read File

License

Apache License

Declaration

static Properties readFile(String fileName) throws Exception 

Method Source Code

//package com.java2s;
/*/*from  w  w  w.j  av  a2  s  .  c o  m*/
 * MODIFICATIONS to the original source have been made by
 * Scott Douglass <scott@swdouglass.com>
 *
 * Copyright 2009 Scott Douglass <scott@swdouglass.com>
 * 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.
 *
 * The original copyright notice and license terms are below.
 */

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

import java.util.Properties;

public class Main {
    static Properties readFile(String fileName) throws Exception {
        File f = new File(fileName);
        if (!f.exists()) {
            throw new IllegalArgumentException("No such file: " + f.getCanonicalPath());
        }
        FileInputStream in = null;
        try {
            Properties prop = new Properties();
            in = new FileInputStream(f);
            prop.load(in);
            return prop;
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (Exception ignore) {
                }
            }
        }

    }
}

Related

  1. readFile(String fileName)
  2. readFile(String filename)
  3. readFile(String filename)
  4. readFile(String filename)
  5. readFile(String fileName)
  6. readFile(String filename)
  7. readFile(String filename)
  8. readFile(String filename)
  9. readFile(String fileName)