0

I want to have a parameter in a @CliCommand which is a network path. Something like \\path\to\newfolder. This folder will then be read and further processed.

However as java interprets backslashes specially, the result will be something like this:

\path\to\newfolder while \t is a backslash and \n is a newline.

Is there a possibility to read a network parameters?

The code looks like this:

   @CliCommand(value="importSifs", help = "Aktivierung von Tasks und Workflows")
    public String importObjects(
      @CliOption(key = "username", mandatory = true) String username,
      @CliOption(key = "password", mandatory = true) String password,
      @CliOption(key = "url", mandatory = true) String url,
      @CliOption(key = "folder", mandatory = true) File folder
Egan Wolf
  • 3,533
  • 1
  • 14
  • 29

1 Answers1

0

To make it valid for Java to read properly, you can replace every \ with \\ somewhere during processing.

String newUrl = url.replace("\\", "\\\\")

Edit:

To replace \n you must use this:

replace("\n", "\\n")

However, you have to define this for all \(char) you can have in url, so some regex could help.

Egan Wolf
  • 3,533
  • 1
  • 14
  • 29
  • Hi Egan, thanks for your comment. I actually tried if this is working. But frankly it does not. If you check the example your command will only replace the first \ in \path. \n or \t will not be recognized. Then I thought to also filter out these special chars and replace every \n also by \\n. This works also. But if you think of an entry in input string \\ \w it will not make a difference as \w will be interpreted as \\w – C. Böhm Jul 19 '17 at 08:38
  • @C.Böhm You are right and I am stupid. Check my edit. Not a perfect answer, but can help you. – Egan Wolf Jul 19 '17 at 08:42
  • @C.Böhm I don't understand your example with `\w`. You can't have something like this in string in Java. – Egan Wolf Jul 19 '17 at 08:55
  • @C.Böhm [This answer](https://stackoverflow.com/a/45054099/5722505) can help you. – Egan Wolf Jul 19 '17 at 09:13