0

I need help with a java properties file that i am using to change the language of my program. The problem is: i want some of the strings in the properties-file to start with a space. however, java automatically trims the leading whitespace. Therefore whenever i am printing out some variable (like a chosen player name: John) followed by a line from the properties-file(won the game) it prints: ''Johnwon the game'', instead of ''John won the game.''

is it possible to avoid this?

Yousama
  • 59
  • 3
  • 1
    Post the code you tried. – forpas Nov 08 '18 at 12:07
  • There are few articles on the net if you search using a string like _"java properties file whitespace"_. Here are some:[reading-properties-file-with-spaced-value](https://coderanch.com/t/376574/java/reading-properties-file) _and_ [reading-properties-file-with-space-null-escaping](http://javahowto.blogspot.com/2013/11/javautilproperties-value.html). – prasad_ Nov 08 '18 at 12:15

2 Answers2

0

Is it possible to avoid this?

No, Leading whitespaces in a property value are automatically trimmed by Java, but trailing whitespaces are preserved. To workaround, you can simply modify your print statement.

Nn12
  • 1
0

You can escape leading space like:

example = \ won the game

However, it would be more conventional to hold the whole formatting string, like:

example = %s won the game
Tim
  • 8,036
  • 2
  • 36
  • 52