JDK-6264243 : File.lineSeparator() to retrieve value of commonly used "line.separator" system property
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 6
  • Priority: P5
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2005-05-02
  • Updated: 2011-04-28
  • Resolved: 2011-04-28
Related Reports
Duplicate :  
The JDK should provide a method which returns the (cached) value of System.getProperty("line.separator").

Many developers end up keeping their own cached copy of getProperty("line.separator"), to avoid the hash table lookup upon every access. It makes sense for the JDK to provide a method which does this, for three reasons:
1. Correctness - It's easy to misspell "line.separator", and the compiler won't check it for you, so you won't find out you misspelled it until runtime.

2. Performance - Currently, many applications call getProperty("line.separator") every time they want to use the system line separator. This is a performance issue because a hash table lookup occurs when calling getProperty. Having a method which returned a cached copy of the property would make it easy to achieve good performance in this regard.

3. Ease of use & cross-platform development - It's easier to type \n than it is to create a new field to store the value of the system property, so many developers do this, which breaks cross-platform compatibility. Making it easy to retrieve the line separator will make it easier to write cross-platform compatible applications.
###@###.### 2005-05-02 18:11:27 GMT

EVALUATION In jdk7 we added System.lineSeparator(), see 6900043.

EVALUATION This problem was previously reported in bug 4192762 which was closed with the following evaluation: For most applications the various readLine methods (in DataInputStream, BufferedReader, and RandomAccessFile) and the various println methods (in PrintStream and PrintWriter) are sufficient. Looking up the "line.separator" property is not so difficult that it deserves being enshrined in a public static field. -- xxxx@xxxx 1999/1/12 APIs which have been added since that evaluation (e.g. java.util.regex, Scanner, and Formatter/printf) continue to make it unnecessary for applications to explicitly require knowledge of the explicit "line.separator". Addition of the requested API is trivial so if there is sufficient interest or perhaps a significant new class of applications which require its explicit knowledge, it should be added as part of JSR-203. ###@###.### 2005-05-02 20:00:59 GMT