Saturday , November 28 2020

java – How to use the line break argument

If you are using a Unix operating system such as GNU / Linux or MacOS, or a Bash shell on any other system (such as Cygwin on Windows), then enclose your command line argument in single quotes, and you can enter any number of newlines and It will still be treated as a single topic:

$ java Helloworld & # 39; line one
line two & # 39; <- this is a single argument with a new embedded line

line one <- print the output on separate lines!
line two

This will not work on the default Windows command processor (cmd.exe). In this case, you may wish to use the following technique.

You can use the StringEscapeUtils.unescapeJava method from Apache Commons Text. Then you will be able to pass the command line arguments and have them interpreted exactly[*] as a literal string in the source code:

static import org.apache.commons.text.StringEscapeUtils.unescapeJava;

public class Helloworld {

public static void main (String[] args) {
System.out.println (unescapeJava (args[0]));

[*] Excluding any remaining bugs in the Apache method.

Source link

Leave a Reply

Your email address will not be published.