一,为啥要学特殊文件
二, 常用方法:读取
三,案例
- import java.io.FileReader;
- import java.util.Properties;
- import java.util.Set;
-
- public class Main {
- public static void main(String[] args) throws Exception {
- //1,创建一个键值对对象
- Properties properties =new Properties();
- System.out.println(properties);
-
- //2,加载数据到对象中去
- properties.load(new FileReader("untitled\\src\\prusidfn\\usfdc.properties"));
- System.out.println(properties);
-
- //3,操作一:根据键取值
- System.out.println(properties.getProperty("张三"));
-
- //4,操作二:遍历
- Set<String>keys = properties.stringPropertyNames();
- for (String key : keys) {
- String value = properties.getProperty(key);
- System.out.println("---->"+value);
- }
-
- }
- }
四,常用方法:写出
五,案例
- import java.io.FileReader;
- import java.util.Properties;
- import java.util.Set;
-
- public class Main {
- public static void main(String[] args) throws Exception {
- //1,创建一个键值对对象
- Properties properties =new Properties();
- System.out.println(properties);
-
- //2,加载数据到对象中去
- properties.load(new FileReader("untitled\\src\\prusidfn\\usfdc.properties"));
- System.out.println(properties);
-
- //3,操作一:根据键取值
- System.out.println(properties.getProperty("张三"));
-
- //4,操作二:遍历
- Set<String>keys = properties.stringPropertyNames();
- for (String key : keys) {
- String value = properties.getProperty(key);
- System.out.println("---->"+value);
- }
-
- }
- }