Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save affandes/3f76ea6cb6c95ba10585cebf1a2f921f to your computer and use it in GitHub Desktop.
Save affandes/3f76ea6cb6c95ba10585cebf1a2f921f to your computer and use it in GitHub Desktop.
import java.io.*;
import java.util.Arrays;
public class ByteStreamVsCharStream {
public static void main(String[] args) {
// Create source
String source = "Affandes";
// Create Byte Stream & Character Stream
InputStream byteStream = new ByteArrayInputStream(source.getBytes());
StringReader characterStream = new StringReader(source);
// Create buffer
byte byteBuff[] = new byte[4];
char charBuff[] = new char[4];
// Read
try {
byteStream.read(byteBuff);
characterStream.read(charBuff);
} catch (IOException e) {
// Error handling
}
// Print
System.out.println(Arrays.toString(byteBuff));
System.out.println(Arrays.toString(charBuff));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment