Created
March 27, 2020 03:23
-
-
Save affandes/997d1fc9aa5dc281a3f928252df31e0e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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