Skip to content

Instantly share code, notes, and snippets.

@mzsanford
Last active January 3, 2016 12:29
Show Gist options
  • Save mzsanford/8463143 to your computer and use it in GitHub Desktop.
Save mzsanford/8463143 to your computer and use it in GitHub Desktop.
Testing `getBytes`
package com.mzsanford;
import java.util.*;
public class Foo {
public static void main(String [] args) throws Exception {
String str = null;
Scanner sc = new Scanner(System.in);
System.out.println("Starting scanner ...");
while (str != null) {
byte[] bytes = str.getBytes("ASCII");
System.out.println("Dumping '" + str + "'");
for (int i=0; i < bytes.length; i++) {
System.out.println(" " + i + ": " + bytes[i]);
}
str = sc.nextLine();
}
}
}
Starting scanner ...
^H # Unicode Mac keyboard Alt+0008
Dumping '
0: 8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment