package elte.java2_utikalauz5.io; import java.io.*; /** Bájt- és karaktertömbök, sztringek. @link.forrásfájl {@docRoot}/../data/io/src Tombok.java @link.letöltés {@docRoot}/../data/io Tombok.jar @since Java 2 Útikalauz programozóknak 1.3 */ public class Tombok { public static void main( String[] args ) throws IOException { fóka(); róka(); baos(); sw(); } public static void sw() throws IOException { StringWriter out = new StringWriter(10); for( int i=97; i<100; i++ ) out.write(i); out.close(); StringReader in = new StringReader(out.toString()); StringBuffer buf = out.getBuffer(); System.out.println(buf); } public static void baos() throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); for( int i=97; i<100; i++ ) out.write(i); out.close(); byte[] b = out.toByteArray(); System.out.write(b); out.writeTo(System.out); String s = out.toString(); System.out.println(s); } public static void róka() throws IOException { char[] t = {'r', 'ó', 'k', 'a'}; CharArrayReader in = new CharArrayReader(t,2,2); int c = in.read(); // c értéke 'k' in.reset(); c = in.read(); // c értéke ismét 'k' (a JDK 1.1-ben 'r') System.out.println(c=='k'); in.close(); } public static void fóka() throws IOException { char[] t = {'r', 'ó', 'k', 'a'}; CharArrayReader in = new CharArrayReader(t); t[0] = 'f'; System.out.println(in.read()=='f'); // "true"-t fog kiírni in.close(); } }