Permalink
Browse files

More weird

  • Loading branch information...
1 parent 71d956d commit 83eaad9dd2e1ccb83a29cb9db56ed2041e19cde2 @aslakhellesoy committed Oct 4, 2012
Showing with 31 additions and 3 deletions.
  1. +10 −2 Ls.java
  2. +21 −1 README.md
View
12 Ls.java
@@ -3,10 +3,18 @@
// See http://jonisalonen.com/2012/java-and-file-names-with-invalid-characters/
class Ls {
- public static void main(String[] args) throws IOException {
+ public static void main(String[] args) throws Exception {
File d = new File("src/main/java/com/aslakhellesoy");
for (File f : d.listFiles()) {
- System.out.printf("%s: %b\n", f.getName(), f.exists());
+ if(args.length > 0 && "hex".equals(args[0])) {
+ System.out.println(toHex(f.getName()));
+ } else {
+ System.out.printf("%s: %b\n", f.getName(), f.exists());
+ }
}
}
+
+ private static String toHex(String arg) throws Exception {
+ return String.format("%040x", new java.math.BigInteger(arg.getBytes("UTF-8")));
+ }
}
View
@@ -48,7 +48,27 @@ JDK 6 gives this:
000000f
```
-Not the same!! Apparntly it's consistent on Linux, but not on OS X.
+Not the same!! Apparently it's consistent on Linux, but not on OS X.
+
+Another thing to try on both JDKs:
+
+```
+javac Ls.java && java Ls hex
+```
+
+JDK 7 gives this:
+
+```
+-0000000000000003c793c479e3375d1959e899f
+```
+
+JDK 6 gives this:
+
+```
+-000000000000000003c793c473c5ad1959e899f
+```
+
+It's clear that this has nothing to do with the terminal. It's something on the Filesystem level or System encoding level.
## Versions:

0 comments on commit 83eaad9

Please sign in to comment.