日期:2014-05-20  浏览次数:20774 次

★★★★★★★简单问题,关于byte与char的区别
//在用于接受用户输入时,只能用byte,不能用char?
import   java.io.*;
public   class   aa
{
public   static   void   main(String   args[])     throws   IOException
{  

byte   aa[]=new   byte[10];       //换成   char   aa[]=new   char[10]会出错,WHY?

int   count=System.in.read(aa);
}

}

------解决方案--------------------
可以用插入的,但是需要转换
char ch[] = new char[10];

Reader r = new Reader(new InputStreamReader(System.in));
int count = r.read(ch);
------解决方案--------------------
byte是字节,char是字符。
------解决方案--------------------
有System.in.read(byte[])没有System.in.read(char[]),byte为8位无符号,char为32位无符号,不存在char到byte的无损自动转换。
------解决方案--------------------
byte用来存放字节char用来存放字符
读取操作有通过字节流的如System.in.read(byte[])
也有读取字符流的
你可以查一下api文档
System.in.read 构造方法没有传char[]值的,所以不能用啊