Normalize End Of Line Character

This post was originally published on Java Code Geeks

1. Introduction

An end-of-line (EOL) character is a special character that marks the end of a line in a text file or a string. Historically, different operating systems denote a different character for EOL. For example, The UNIX system defines EOL as “n” (NewLine ), and Apple MacOS chooses “r” (CarriageReturn) while the Microsoft Windows system defines “rn” (CRLF). Out of these three EOL, the “n” is the most used. When java programs process text data from different operating systems with different EOL characters, normalizing the EOL characters ensures consistency in data processing and avoids unexpected behavior. In this example, I will demonstrate how to normalize end of line character via the java.lang.System.lineSeparator method as it returns the system-dependent line separator string.

2. Maven Set up

In this step, I will set up a maven project to print out 3 text lines.


4.0.0 org.zheng.demo demoEOL 0.0.1-SNAPSHOT org.apache.commons commons-lang3 3.14.0

I will create a TestData class which builds 3 text lines with a different EOL character with the buildAStringWithEol method.

package demoEOL; public class TestData { public static String EOL_MAC = “r”; public static String EOL_UNIX = “n”; public static String EOL_WIN = “rn”; public static String buildAStringWithEol(String eolChar) { StringBuilder sb =

Read the rest of this post, which was originally published on Java Code Geeks.

Previous Post

Game Theory – The Secret Weapon of Blockchain Developers

Next Post

[FREE EBOOKS] PowerShell 7 Workshop, The DevSecOps Playbook & Four More Best Selling Titles