Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: possible to line break in a properties file?

People also ask

How read properties file line by line in Java?

Java Read File line by line using BufferedReader We can use java.io.BufferedReader readLine() method to read file line by line to String. This method returns null when end of file is reached. Below is a simple program showing example for java read file line by line using BufferedReader.

How do I escape properties file?

would be the two-character key ":=". Line terminator characters can be included using \r and \n escape sequences. Any white space after the key is skipped; if the first non-white space character after the key is '=' or ':' , then it is ignored and any white space characters after it are also skipped.

How do I comment in application properties file?

In addition to properties and blank lines, the application. properties field may contain comments. To comment a line, just put the hash character at the beginning of a line.

What is in properties file?

properties file is a simple collection of key-value pairs that can be parsed by the java. util. Properties class. Properties files are widely used for many purposes in all kinds of Java applications, often to store configuration or localization data.


A backslash at the end of a line lets you break across multiple lines, and whitespace that starts a line is ignored:

myStr = Hello \
        World

Note: the backslash needs to be at the very end of the line; it must be the last character, no spaces after it, etc.

The Java docs put it this way:

A logical line holds all the data of a key-element pair, which may be spread out across several adjacent natural lines by escaping the line terminator sequence with a backslash character \.

...

If a logical line is spread across several natural lines, the backslash escaping the line terminator sequence, the line terminator sequence, and any white space at the start of the following line have no affect on the key or element values.


myStr = Hello \
        World

The backslash tells the application to continue reading the value onto the next line. ^^


You need to use \n\ as a solution.

First two symbols \n - new line for string, third \ - multi-line in properties file.

For example (in application.properties):

mail.bodyText=Hello.\n\
This is notification.