Skip to content

Instantly share code, notes, and snippets.

@tomoTaka01
Last active June 21, 2016 07:04
Show Gist options
  • Save tomoTaka01/17c5a0141697c4064e117ca3adc0b490 to your computer and use it in GitHub Desktop.
Save tomoTaka01/17c5a0141697c4064e117ca3adc0b490 to your computer and use it in GitHub Desktop.
Confirm line separator for Windows and Mac, since the below code is executed in Mac.
package com.test;
public class PrintLineSeparator {
public static void main(String... args) {
new PrintLineSeparator().printCrLf();
}
private void printCrLf() {
String crlf = "\r\n";
String lf = System.getProperty("line.separator");
System.out.print(String.format("crlf=%4h", crlf));
printBinary(crlf);
System.out.print(String.format(" lf=%4h", lf));
printBinary(lf);
}
private void printBinary(String val) {
char[] chars = val.toCharArray();
for (int i = 0; i < chars.length; i++) {
int intVal = (int) chars[i];
System.out.print(String.format(" %s", Integer.toBinaryString(intVal)));
}
System.out.println("");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment