# Java集合Map之Properties **Repository Path**: fpfgitmy_admin/java-collection-map-properties ## Basic Information - **Project Name**: Java集合Map之Properties - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2021-04-28 - **Last Updated**: 2021-04-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README #### Properties处理属性文件 + Properties类是Hashtable的子类,该对象用于处理属性文件 + 由于属性文件里的key、value都是字符串类型,所以Properties里的key和value都是字符串类型 + 存取数据时,建议使用setProperty(String key,String value)方法和getPropertry(String key)方法 ##### 获取项目下属性文件 1. 创建属性文件(在项目的下一级目录) ![输入图片说明](https://images.gitee.com/uploads/images/2021/0428/140726_99dd135b_1942182.png "屏幕截图.png") 2. 编写内容 ``` name=root哈哈 password=123 ``` 3. 读取属性值(如果有中文的话,要在idea setting中配置File Encodings) ``` package com.felixfei.study.test; import java.io.FileInputStream; import java.io.IOException; import java.util.Properties; /** * @describle */ public class TestProperties { public static void main(String[] args) { Properties properties = new Properties(); // 方式一:获取项目下的属性文件的值 FileInputStream fileInputStream = null; try { fileInputStream = new FileInputStream("jdbc.properties"); properties.load(fileInputStream); } catch (IOException e) { e.printStackTrace(); } finally { if (fileInputStream != null) { try { fileInputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } String name = properties.getProperty("name"); System.out.println(name); } } ```