back slash properties file new line

FROM HERE

You add a slash (“\”) to continue the value on the next line.

Take the following properties file :
[props.properties]

prop1=first line of prop1 \
second line of prop1\
third line of prop1
prop2=first line of prop2 \n \
second line of prop2 \n \
third line of prop2

A program to read the properties file :
[Hello.java]

public class Hello {
    public static void main(String args[]) throws Exception{
      Hello h = new Hello();
      h.doit();
      }
    public void doit() throws Exception{
      // properties in the classpath
      java.util.Properties props = new java.util.Properties();
      java.net.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"));
      }
}

The output

>java Hello
prop1 :
 first line of prop1 second line of prop1third line of prop1
prop2 :
 first line of prop2
 second line of prop2
 third line of prop2
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s