package com.thinkgem.jeesite.qmy; import java.io.IOException; import com.opensymphony.module.sitemesh.util.CharArrayReader; import com.opensymphony.module.sitemesh.util.CharArrayWriter; public class CharArrayWriterTest { public static void main(String[] args) { String s = "这是java串"; char[] dst = new char[s.length()];//定义字符串 s.getChars(0, s.length(), dst, 0);//将字符串转变为字符数组 CharArrayReader charArrayReader = new CharArrayReader(dst);//输入流实例 CharArrayWriter charArrayWriter = new CharArrayWriter();//输出流实例 try { while(charArrayReader.ready()){ charArrayWriter.write(charArrayReader.read());//将输入流的内容写入输出流 } } catch (IOException e) { e.printStackTrace(); } //将输出流转换为字符数组 char[] temp_char = charArrayWriter.toCharArray(); System.out.println("字符数组的输出————————"); //将输出流转换为字符串 String temp_str = charArrayWriter.toString(); for (int i = 0; i < temp_char.length; i++) { System.out.print(temp_char[i]); } System.out.println(); System.out.println("字符串的输出——————————"); System.out.println(temp_str); } }