@Test
  public void testState() throws IOException {
    final File fcontent = File.createTempFile("foo", "bar");
    final Properties properties = new Properties();
    final Date dt = new Date();

    properties.put("int", 10453);
    properties.put("long", 1000000L);
    properties.put("date", dt);

    final OutputStream out = new FileOutputStream(fcontent);
    properties.store(out);

    final Properties loadProperties = new Properties();

    final InputStream in = new FileInputStream(fcontent);
    loadProperties.load(in);

    assertNotNull(properties.get("int"));
    assertNotNull(properties.get("long"));
    assertNotNull(properties.get("date"));

    assertEquals(10453, properties.get("int"));
    assertEquals(1000000L, properties.get("long"));
    assertEquals(dt, properties.get("date"));
  }
示例#2
0
 public void writeProperties(Map<?, ?> properties) {
   Properties props = new Properties();
   props.putAll(properties);
   try {
     FileOutputStream stream = new FileOutputStream(this);
     try {
       props.store(stream, "comment");
     } finally {
       stream.close();
     }
   } catch (IOException e) {
     throw new RuntimeException(e);
   }
 }