Java Collection How to - Have a multi-line value in a properties file








Question

We would like to know how to have a multi-line value in a properties file.

Answer

add a slash \ to continue the value on the next line.

prop1=line1\
line2\
line3

Code

/*from   www  .  ja  va 2 s. com*/
import java.net.URL;
import java.util.Properties;

public class Main {
  public static void main(String args[]) throws Exception {
    Properties props = new Properties();
    URL url = ClassLoader.getSystemResource("props.properties");
    props.load(url.openStream());
    System.out.println("prop1 :\n " + props.get("prop1"));
    System.out.println("prop2 :\n " + props.get("prop2"));
  }
}