Last active
December 16, 2022 14:28
-
-
Save goxr3plus/6923c59b008113d671e06e2787bccd99 to your computer and use it in GitHub Desktop.
Detect END OF LINE (EOL) in File with Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Eol | |
{ | |
WINDOWS, | |
MAC, | |
LINUX | |
} | |
Reader r = new FileReader("file absolute path"); | |
int i = -1; | |
Eol eol = null; | |
// Read each character until EOL reached | |
while ((eol == null) && ((i = r.read()) != -1)) | |
{ | |
if (i == '\r') | |
{ | |
i = r.read(); | |
if (i == '\n') | |
eol = Eol.WINDOWS; | |
else | |
eol = Eol.MAC; | |
} | |
else if (i == '\n') | |
{ | |
eol = Eol.LINUX | |
} | |
} | |
r.close(); | |
System.out.println(eol); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment