txt文件操作

// txt文件操作
Properties prop = new Properties();
String s = "Height=200";
String s2 = "Width=15";
FileOutputStream fos = new FileOutputStream("properties.txt");
fos.write(s.getBytes());
fos.write("\r\n".getBytes());
fos.write(s2.getBytes());

FileInputStream fis = new FileInputStream("properties.txt");
prop.load(fis); // txt:从输入字节流读取
prop.list(System.out);
System.out.println(prop.get("Height"));

 

xml文件操作

// xml文件操作
Properties prop = new Properties();
prop.put("Height", "200");
prop.put("Width", "15");
FileOutputStream fos = new FileOutputStream("properties.xml");
prop.storeToXML(fos, "Properties Example"); // xml:输出流写入

FileInputStream fis = new FileInputStream("properties.xml");
prop.loadFromXML(fis); // xml:从输入流读取properties
prop.list(System.out);

Set<String> set = prop.stringPropertyNames();
System.out.println(set)

 

相关文章:

  • 2022-02-13
  • 2021-04-09
  • 2021-11-14
  • 2021-09-07
  • 2021-07-08
  • 2021-07-21
  • 2022-12-23
猜你喜欢
  • 2022-01-30
  • 2021-11-22
  • 2021-09-13
  • 2021-10-03
  • 2022-02-17
  • 2021-07-08
相关资源
相似解决方案