Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save affandes/997d1fc9aa5dc281a3f928252df31e0e to your computer and use it in GitHub Desktop.
Save affandes/997d1fc9aa5dc281a3f928252df31e0e to your computer and use it in GitHub Desktop.
import java.io.*;
public class ByteStreamVsCharStream {
public static void main(String[] args) {
// Input source
String souce = "Affandes";
// Create Byte Stream and Character Stream
ByteArrayInputStream inputByte = new ByteArrayInputStream(souce.getBytes());
StringReader inputReader = new StringReader(souce);
try {
// Create container/buffer
byte byteBuff[] = new byte[5];
char charBuff[] = new char[5];
// Read input source
inputByte.read(byteBuff);
inputReader.read(charBuff);
// Output container/buffer
System.out.println("byteBuff[0] = " + byteBuff[0]);
System.out.println("charBuff[0] = " + charBuff[0]);
} catch (IOException ex) {
// Error handling
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment