test/java/io/PrintStream/EncodingConstructor.java
Print this page
rev 3565 : 7022624: use try-with-resources in java.io tests
Reviewed-by: XXX
@@ -32,15 +32,15 @@
public class EncodingConstructor {
public static void main(String args[]) throws Exception {
ByteArrayOutputStream bo = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(bo, false, "UTF-8");
String s = "xyzzy";
int n = s.length();
+ try (PrintStream ps = new PrintStream(bo, false, "UTF-8")) {
ps.print(s);
- ps.close();
+ }
byte[] ba = bo.toByteArray();
if (ba.length != n)
throw new Exception("Length mismatch: " + n + " " + ba.length);
for (int i = 0; i < n; i++) {
if (ba[i] != (byte)s.charAt(i))