1、将数据设置并保存到Properties文件
String path = PropertiesTools.class.getResource(filePath).getPath();
File file = new File(path);
//获取全路径
String canonicalPath = file.getCanonicalPath();
//通过Files获取文件的输出流
OutputStream fos = Files.newOutputStream(Paths.get(canonicalPath));
//设置属性值
Properties prop = new Properties();
prop.setProperty("id", "123");
prop.setProperty("name", "张三");
//将此 Properties 表中的属性列表(键和元素对)写入输出流,将设置的属性值通过输出流保存到文件中
prop.store(fos, null);
2、获到Properties文件的属性值
String path = PropertiesTools.class.getResource(filePath).getPath();
File file = new File(path);
//获取全路径
String canonicalPath = file.getCanonicalPath();
//通过Files获取文件输入流
InputStream is = Files.newInputStream(Paths.get(canonicalPath));
Properties prop = new Properties();
//从输入流中读取属性列表
prop.load(is);
String id = prop.getProperty("id");
String name = prop.getProperty("name");
多看jdk api,多点进去看源码,多我修炼自已的内功心法。