Skip to content

Commit

Permalink
More weird
Browse files Browse the repository at this point in the history
  • Loading branch information
aslakhellesoy committed Oct 4, 2012
1 parent 71d956d commit 83eaad9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
12 changes: 10 additions & 2 deletions Ls.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")));
}
}
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down

0 comments on commit 83eaad9

Please sign in to comment.