Last active
June 21, 2016 07:04
-
-
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.
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
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