Java CharArrayWriter类的简介说明
下文笔者将讲述CharArrayWriter类的简介说明,如下所示:
例:
CharArrayReader类的功能: 用于写入数据符 可实现将流输出到数组
CharArrayWriter类的构造函数
CharArrayWriter() CharArrayWriter(int initialSize)
CharArrayWriter类的方法
CharArrayWriter append(CharSequence csq, int start, int end) |
CharArrayWriter append(char c) |
CharArrayWriter append(CharSequence csq) |
void close() |
void flush() |
void reset() |
int size() |
char[] toCharArray() |
String toString() |
void write(char[] buffer, int offset, int len) |
void write(int oneChar) |
void write(String str, int offset, int count) |
void writeTo(Writer out) |
public static void main(String[] args) { String s = "java265.com是我最爱的网站"; 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); }
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。