Phone_Number.java 使用或覆盖了以过时的API
/* filename:Phone_Number.java
description:从标准输入中得到名字和号码,存入文件Phone.dat中
...
*/import java.io.*;
public class Phone_Number
{
static FileOutputStream fos;
public static final int lineLength=81;
public static void main(String args[]) throws IOException
{ byte[] phone=new byte[lineLength];
byte[] name=new byte[lineLength];
int i;
fos=new FileOutputStream("phone.dat");
while(true)
{ System.err.println("Enter a name(enter 'over' to quit)");
readLine(name);
if("over".equalsIgnoreCase(new String(name,0,0,4)))
{break;}
System.err.println("Enter the phone number");
readLine(phone);
for(i=0;phone[i]!=0;i++)
{fos.write(phone[i]);}
fos.write(',');
for(i=0;name[i]!=0;i++)
{fos.write(name[i]);}
fos.write('\n');
}
fos.close();
}
public static void readLine(byte line[]) throws IOException
{int i=0,b=0;
while((i<(lineLength-1))&&((b=System.in.read())!='\n'))
{line[i++]=(byte)b;
}
line[i]=(byte)(0);
}
}
/* filename:Phone_Number.java
description:从标准输入中得到名字和号码,存入文件Phone.dat中
...
*/import java.io.*;
public class Phone_Number
{
static FileOutputStream fos;
public static final int lineLength=81;
public static void main(String args[]) throws IOException
{ byte[] phone=new byte[lineLength];
byte[] name=new byte[lineLength];
int i;
fos=new FileOutputStream("phone.dat");
while(true)
{ System.err.println("Enter a name(enter 'over' to quit)");
readLine(name);
if("over".equalsIgnoreCase(new String(name,0,0,4)))
{break;}
System.err.println("Enter the phone number");
readLine(phone);
for(i=0;phone[i]!=0;i++)
{fos.write(phone[i]);}
fos.write(',');
for(i=0;name[i]!=0;i++)
{fos.write(name[i]);}
fos.write('\n');
}
fos.close();
}
public static void readLine(byte line[]) throws IOException
{int i=0,b=0;
while((i<(lineLength-1))&&((b=System.in.read())!='\n'))
{line[i++]=(byte)b;
}
line[i]=(byte)(0);
}
}
解决方案 »
- 紧急求助-- 点击按钮 运行 bat文件,
- 各位前辈,小生有点问题!
- Java如何判断有乱码,是否有Oracle那种ASCIISTR那样的函数
- 纯粹散分没意思, 大家还是来讨论个问题吧! (200分)
- 怎么让JTable的数据动态初始化
- 一个Reflection的问题,invoke对象中的对象的方法
- *****弟兄们,遇到难题了,用eclipse用其内置的cvs通过代理服务器登录国外的cvs服务器的问题,
- 刚看到一篇所谓的精华文章,关于package和classpath的,在下觉得有话要说,来着有分!
- 图形操作的一个问题
- 问:在b/s结构中,如果要显示报表(包括需要饼图,直方图类),你通常会考虑怎么做?
- 变量交换问题~送分题
- Properties类的简单问题
if("over".equalsIgnoreCase(new String(name,0,0,4)))
是因为你出现了 new String(name, 0, 0, 4)
API描述:
String(byte[] ascii, int hibyte, int offset, int count)
已过时。 该方法无法将字节正确地转换为字符。从 JDK 1.1 开始,完成该转换的首选方法是使用带有 Charset、字符集名称,或使用平台默认字符集的 String 构造方法。
String(byte[] bytes, int offset, int length, String charsetName)
通过使用指定的字符集解码指定的 byte 子数组,构造一个新的 String。
用这个 new String(name, 0, 4, "utf16") 代替
if("over".equalsIgnoreCase(new String(name,0,4,"ISO8859-1")))就OK了