Javaは、プロパティファイルを読みます

 

パブリック静的プロパティloadProps(文字列filename){ 
        プロパティのプロパティは= NULL; 

        InputStream InputStreamは= NULL; 
        {試みる
            のinputStream =にThread.currentThread()をgetContextClassLoader()getResourceAsStream(ファイル名)。
            もし(InputStreamの== nullの){ 
                新しいFileNotFoundExceptionを(ファイル名)投げます。
            } 
            プロパティ=新しいプロパティ(); 
            Properties.load(のinputStream)。

        }キャッチ(のIOExceptionのEX){ 
            ex.printStackTrace(); 
        }最後に{ 
            closeStream(のinputStream)。
        } 
        プロパティを返します。
    }

    プライベートの静的な無効closeStream(InputStream InputStreamは){ 
        場合(!のinputStream = NULL){ 
            {しようと
                inputStream.closeを(); 
            }キャッチ(IOExceptionを電子){ 
                e.printStackTrace(); 
            } 
        } 
    }

  

おすすめ

転載: www.cnblogs.com/Brake/p/11442828.html