---
title: "UTIL工具类"
author: "Dragonmandance"
date: "2017-02-08T17:59:16Z"
tags: []
categories: ["编程语言"]
slug: "util"
draft: false
lastmod: "2017-02-08T17:59:16Z"
id: 2356162
url: "https://dragonmandance.iteye.com/blog/2356162"
---

**properties文件读取**

```java

public class PropertiesUtil {
	private static final LoggerAdapter logger = LoggerAdapterFactory
			.getLogger(MTPLogType.WEB);
	/**
	 * 读取properties文件，返回Map
	 * @param resourceFileName
	 * @return
	 */
	public static Map<String, String> loadFile(String resourceFileName) {
		Map<String, String> data = new HashMap<String, String>();
		InputStream is = null;
		try {
			is = Thread.currentThread().getContextClassLoader()
					.getResourceAsStream(resourceFileName);

			Properties properties = new Properties();
			properties.load(is);
			for (Map.Entry<Object, Object> entry : properties.entrySet()) {
				data.put((String) entry.getKey(), (String) entry.getValue());
			}
			return data;
		} catch (Exception e) {
			logger.error("load "+resourceFileName+" error", e);
			return null;
		} finally {
			if (is != null) {
				try {
					is.close();
					is = null;
				} catch (IOException e) {
					logger.error("", e);
				}
			}
		}
	}
}
```