124

In a Java .properties file we can do single line comments with #.

Is there any way by which we can do multi-line comments?

1

8 Answers 8

185

Unfortunately not! Java properties file only have single line # comments.

2
43

If you use Eclipse, you can select multiple lines and comment all with a shortcut (Ctrl+/ by default). Same shortcut uncomments the lines, but you have to pay attention no to select any empty line, which will cause the non-empty ones to get commented more than once.

These apply to Eclipse, but I guess many IDE:s and some editors offer similar functionality.

5
  • 2
    Thanks for the shortcut.I am fine with using eclipse, and letting eclipse auto-generate the multi-line comment. Feb 16, 2016 at 7:23
  • Very useful. Thanks.
    – Uvaise
    Jun 30, 2017 at 10:23
  • 1
    What about intellij IDEA, there is any shortcut to comment properties file? Jul 4, 2018 at 12:20
  • Yes, there is, search for comment with line comment in Preferences > Keymap. It should probably be Ctrl + / (Cmd + / for mac).
    – zaboco
    Jul 4, 2018 at 13:26
  • It works fine with STS 4 IDE too! Dec 20, 2022 at 14:13
10

.properties files do not have multiline comments.

Since JDK 1.5 Properties have XML support, and XML format supports multiline comments. See javadocs.

5

I have made a class that handles comments in properties. Both general header comments and comments for individual properties.

Have a look at : CommentedProperties JavaDoc

The jar file can be downloaded here : Download jar file from sourceforge

3

We can use Ctrl+/ to comment multiple lines in properties file. But it will put # for blank line also.

1
  • 1
    You can't just state this as a general fact. Each editor has different default key mappings.
    – Neuron
    Jun 23, 2018 at 23:46
1

Select the content to comment out and press ctrl+/ on the eclipse editor

0

If you are using Eclipse there is this shortcut Ctrl+Shift+A that turns on selecting a column, so you can just drag through all the rows you need to comment and add # (this will add it to all rows). It will be the same when you want to delete the #. To turn off the column selecting mode you have to again press Ctrl+Shift+A.

-9

single line comment using #

multiline comment using <!-- -->

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.