Why does the first example print the string 12345 but the second one doesn't?
public static void main(String[] args) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
baos.write("12345".getBytes());
} catch (Exception e) {
e.printStackTrace();
}
String output = baos.toString();
System.out.println(output);
}
public static void main(String[] args) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(baos);
try {
osw.write("12345");
} catch (Exception e) {
e.printStackTrace();
}
String output = baos.toString();
System.out.println(output);
}
Am I not using the OutputStreamWriter for its correct use?
Thanks