0

Good morning, i'm making a program for backup. In the config file i need specify N source directories and theyr destination directories, like this:

source="source dir", "destination drive1", "destination drive2"
source="source dir2", "destination drive", "destination drive2"

but in properties i can have only one value for a key, so i use different keys for source1, source2 etc.

there is a workaround for this?

ps what is the correct way to split the above string "source dir", "destination drive1", "destination drive2" if i split with " it's easy, but if i have something like

"i feel ""good"" because i'm a java programmer", "i feel "very bad" because i'm a java programmer"

i can't use string.split("""") because the " in "good" will split the string.

thank you very much

3 Answers3

0

For splitting by " symbol :

String[] split = s.split("\"");

And if you want to have " sign in String you need to wtite \" instead ".

Ashot Karakhanyan
  • 2,804
  • 3
  • 23
  • 28
0

You could save it to a JSON file if you want. A full example to save and read in JSON.Simple Example – Read And Write JSON.

In another way, you need escape the double quotes on save. See https://stackoverflow.com/a/10452463/870248

Community
  • 1
  • 1
Paul Vargas
  • 41,222
  • 15
  • 102
  • 148
0

I see three solutions.

Many Keys, One Value

source1a="source"
source1b="destination one"
source1c="destination two"
source2a="source"
source2b="destination one"
source2c="destination three"

One Key, One Value

source1=source,destination one,destination two
source2=source,destination one,destination two

For this, use String.split(",") to parse the values.

XML

Because properties are so 20th century.

<configills>
  <blam hoot="source">
    <destination value="destination one"/>
    <destination value="destination two"/>
  </blam>
  <blam hoot="source2">
    <destination value="destination one"/>
    <destination value="destination two"/>
  </blam>
</configills>
DwB
  • 37,124
  • 11
  • 56
  • 82
  • If I was doing a simple xml design; SAX seems fine. For something more complicated check out JAXB. Also, Spring has great JAXB support (and Castor and JiBX as well as others). – DwB Feb 04 '14 at 19:49