zoukankan      html  css  js  c++  java
  • 字符流的学习

    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);
            
        }
    }
  • 相关阅读:
    版本控制之GitHub亲手实验总结
    Java的HashMap是如何实现的?
    Junit
    由swap引发的关于按值传递和引用传递的思考与总结
    C++了解free和delete
    GitHub使用教程
    Oracle下SQL学习笔记
    Flappy Bird
    尾递归与Continuation(转载)
    十步完全理解SQL(转载)
  • 原文地址:https://www.cnblogs.com/bksqmy/p/4698614.html
Copyright © 2011-2022 走看看