int ch=0;
int pos=0;
String strInfo=null;
while(true)
{
ch =System.in.read(); //我的问题在这里
System.out.println(Integer.toHexString(ch));
switch(ch)
{
case '\r':
break;
case '\n':
strInfo= new String(buf,0,pos);
for(int i=0;i<strInfo.length();i++)
{
System.out.println(Integer.toHexString
((int)strInfo.charAt(i)));
}
System.out.println(strInfo);
for(int i=0;i<pos;i++)
System.out.write(buf[i]);
System.out.println();
return;
default:
buf[pos++]=(byte)ch;
//请问为什么switch(ch)中的ch要int类型定义,为什么不用byte?另:有人回答说“用int 是为了防止返回 -1 的情况”,我不懂什么意思!
byte 范围不是也包括 -1 吗?
int pos=0;
String strInfo=null;
while(true)
{
ch =System.in.read(); //我的问题在这里
System.out.println(Integer.toHexString(ch));
switch(ch)
{
case '\r':
break;
case '\n':
strInfo= new String(buf,0,pos);
for(int i=0;i<strInfo.length();i++)
{
System.out.println(Integer.toHexString
((int)strInfo.charAt(i)));
}
System.out.println(strInfo);
for(int i=0;i<pos;i++)
System.out.write(buf[i]);
System.out.println();
return;
default:
buf[pos++]=(byte)ch;
//请问为什么switch(ch)中的ch要int类型定义,为什么不用byte?另:有人回答说“用int 是为了防止返回 -1 的情况”,我不懂什么意思!
byte 范围不是也包括 -1 吗?
解决方案 »
- 怎么获取某一个Java类的实例个数
- 高人前辈们请进来指点下一道JAVA的代码修改
- 有朋友过这个网站吗?http://www.ttjj.com/index.php 我发现它的技术还真是不错!!
- BT下载张孝祥java视频教程!!!
- 请问各位在在配制apache跟modssl是要一个ApacheModuleSSL.dll请给一个 急用?100感谢
- 如何把字符的ASC转换成十六进制?
- 怎么得到一个String?
- 问一个wait()的问题,
- 有人用Sybase+jConnect吗?使用时有哪些需要注意的?请指教下小弟!
- java中基于socket的问题
- notify问题
- 着急啊各位,问题很长时间了没解决,JTextArea删除字符串时,如何得到删除的内容,在debug窗口中能看到删除的内容,但是我不知道怎么得到?
读出来的就是字符的ASSIC码,当然用int是最好的
switch("")
jdk7以后可以接受字符串。
那个告诉你为了防止-1的人是在忽悠你