Java: possible to line break in a properties file?

前端 未结 3 963
天命终不由人
天命终不由人 2021-01-31 01:00

Is it possible to continue a long string on the next line in a Java properties file?

e.g., somehow

myStr=Hello
      World

and when I g

相关标签:
3条回答
  • 2021-01-31 01:29
    myStr = Hello \
            World
    

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

    0 讨论(0)
  • 2021-01-31 01:35

    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
    

    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 \.

    0 讨论(0)
  • 2021-01-31 01:37

    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.
    
    0 讨论(0)
提交回复
热议问题