프로그래밍 정리/자바

StringReader와 StringWriter

주누다 2013. 6. 2. 03:18
반응형

- 메모리에 대한 문자열 데이터의 입출력을 담당


.getBuffer().reverse() -> 문자데이터 역방향

========================================================================================================


import java.io.IOException;

import java.io.StringReader;

import java.io.StringWriter;



public class StringRWTest {

public static void main(String[] args) throws IOException {

int ch;

String str = "Hello!";

StringReader sr = new StringReader(str);

StringWriter sw = new StringWriter();

while( (ch = sr.read()) != -1){

sw.write(ch);

System.out.println("read : [" + (char)ch + "]" + ", write : [" + sw.toString() +"]");

}

System.out.println("순방향 출력 : " + sw.toString());

System.out.println("역방향 출력 : " + sw.getBuffer().reverse());

System.out.println("순방향 출려 : " + sw.getBuffer());

System.out.println("역방향 출력 : " + sw.getBuffer().reverse());

}

}



반응형