0

As suggested by this answer:

You can call

System.setProperty("line.separator", "\r\n");

in order to set the system property inside your code.

it is quite easy to make a Java program output the desired line endings. However, I see no reason why one shouldn't be able to change that environment variable, say, as a compiler setting?

Community
  • 1
  • 1
Christian Neverdal
  • 5,655
  • 6
  • 38
  • 93

1 Answers1

5

Because that's simply not how environment variables work, by definition. Environment variables are dictated by the runtime environment, not by the compiler or any compile-time setting.

Many operating systems use environment variables to pass configuration information to applications. Like properties in the Java platform, environment variables are key/value pairs, where both the key and the value are strings. The conventions for setting and using environment variables vary between operating systems, and also between command line interpreters.

Matt Ball
  • 354,903
  • 100
  • 647
  • 710
  • but then could I possibly EXPORT=... something? Or is there just no way of altering this (given, of course, that the Java program itself does not alter it). – Christian Neverdal Apr 08 '13 at 19:23
  • Of course. The `EXPORT` equivalent in Java is the `System.setProperty()` method call you already noted. – Matt Ball Apr 08 '13 at 19:23
  • Do you happen to know what the correct name is? EXPORT whatwhat=\r\n? – Christian Neverdal Apr 08 '13 at 19:25
  • 1
    Pass it as a JVM argument: `-Dline.separator=""`. You can get a CRLF on your clipboard on Mac systems with the following terminal command: `echo -en "\x0d\x0a" | pbcopy` – Matt Ball Apr 08 '13 at 19:44