Skip to content

Instantly share code, notes, and snippets.

@goxr3plus
Last active December 16, 2022 14:28
Show Gist options
  • Save goxr3plus/6923c59b008113d671e06e2787bccd99 to your computer and use it in GitHub Desktop.
Save goxr3plus/6923c59b008113d671e06e2787bccd99 to your computer and use it in GitHub Desktop.
Detect END OF LINE (EOL) in File with Java
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