六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 35|回复: 0

java 将字符数组转成字符串

[复制链接]

升级  46%

98

主题

98

主题

98

主题

举人

Rank: 3Rank: 3

积分
338
 楼主| 发表于 2013-1-26 13:59:23 | 显示全部楼层 |阅读模式
public   class   Test{   
  public   static   void   main(String[]   args){   
          char[]   data={a,b,c};   
          String   s=new   String(data);   
          System.out.println(s);   
  }   
}



package cn.rg.demo.test;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;

public class writeFile {
public static void main(String[] args) throws IOException {        
      
        BufferedInputStream in = new BufferedInputStream(new FileInputStream("C:/Documents and Settings/iwin/桌面/work/ff85c21a4810499abc09854397b85c47.html"));        
        ByteArrayOutputStream out = new ByteArrayOutputStream(1024);        
      
        System.out.println("Available bytes:" + in.available());        
      
        byte[] temp = new byte[1024];        
        int size = 0;        
        while ((size = in.read(temp)) != -1) {        
            out.write(temp, 0, size);        
        }        
        in.close();        
      
        byte[] content = out.toByteArray();
        String   s=new   String(content);  
        System.out.println(s);
        System.out.println("Readed bytes count:" + content.length);        
    }         
}
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表