java中socket读取数据问题 调试助手发送数据fe fe fe 69使用BufferedInputStream读取时,得到的字节数组中的数据是66 65 66 65 66 65 36 39,怎样才能得到fe fe fe 69socketjava 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 转一下字节BufferedInputStream bf=new BufferedInputStream(fs);FileOutputStream os=new FileOutputStream("e:/os.txt");byte[] buffer = new byte[1024]; int count = 0; while((count = bf.read(buffer)) >= 0){ os.write(buffer, 0, count);} 也可以直接使用DataInputStreamReader或BufferedReader等读取。 我着一个笨办法:import java.util.Arrays;public class ByteArrayToHex{ public static void main(String[] args){ byte[] result; byte[] original = {0x66, 0x65, 0x66, 0x65, 0x66, 0x65, 0x36, 0x39};//字节数组中的数据,为16进制. result = change(original); System.out.println(Arrays.toString(result));//显示。 } public static byte[] change(byte[] b){ byte[] out = new byte[b.length/2];//定义返回数组的大小。 byte h,l; //两个临时变量。 for(int i=0; i<b.length; i+=2){ if(b[i]>=97&&b[i]<=102){ h = (byte)(b[i]-97+10);//把高位的ascii码,转成其代表的字符。a-f }else if(b[i]>=65 && b[i]<=69){ h = (byte)(b[i]-65+10);//A-F. }else{ h = (byte)(b[i]-48);//0-9 } h = (byte)(h<<4);//左移4位,放在高位。 if(b[i+1]>=97 && b[i+1]<=102){ l = (byte)(b[i+1]-97+10);//把低位的ascii码,转成其代表的字符或数字。a-f }else if(b[i+1]>=65 && b[i+1]<=69){ l = (byte)(b[i+1]-65+10);//(A-F). }else{ l = (byte)(b[i+1]-48);//0-9 } out[i/2]=(byte)(h+l);//合并成一个字节。 }//end for return out; }} 匿名内部类使用final参数的问题 java 多线程 BlockingQueue ??????? 怎样获取图像文件的大小啊? 我遇到一个很奇怪的问题,有关清空文件夹的 郁闷,我的计算机上面只有JDK1.3.1再加个XP,可以编些什么东西啊? 请高手帮忙看看,有什么修改或更好的写法,总觉得有不对劲 jtable中选取一行的事件 概念問題,送分! 如果你认为java的基础学的好,请看这个例子的结果是什么? 恩!!(step1 learning java) java同一个项目里不同包之间如何访问变量 迅雷下载资源,没速度,很无语
BufferedInputStream bf=new BufferedInputStream(fs);
FileOutputStream os=new FileOutputStream("e:/os.txt");
byte[] buffer = new byte[1024];
int count = 0;
while((count = bf.read(buffer)) >= 0){
os.write(buffer, 0, count);
}
public class ByteArrayToHex{
public static void main(String[] args){
byte[] result;
byte[] original = {0x66, 0x65, 0x66, 0x65, 0x66, 0x65, 0x36, 0x39};//字节数组中的数据,为16进制.
result = change(original);
System.out.println(Arrays.toString(result));//显示。
} public static byte[] change(byte[] b){
byte[] out = new byte[b.length/2];//定义返回数组的大小。
byte h,l; //两个临时变量。
for(int i=0; i<b.length; i+=2){
if(b[i]>=97&&b[i]<=102){
h = (byte)(b[i]-97+10);//把高位的ascii码,转成其代表的字符。a-f
}else if(b[i]>=65 && b[i]<=69){
h = (byte)(b[i]-65+10);//A-F.
}else{
h = (byte)(b[i]-48);//0-9
}
h = (byte)(h<<4);//左移4位,放在高位。 if(b[i+1]>=97 && b[i+1]<=102){
l = (byte)(b[i+1]-97+10);//把低位的ascii码,转成其代表的字符或数字。a-f
}else if(b[i+1]>=65 && b[i+1]<=69){
l = (byte)(b[i+1]-65+10);//(A-F).
}else{
l = (byte)(b[i+1]-48);//0-9
}
out[i/2]=(byte)(h+l);//合并成一个字节。
}//end for
return out;
}
}