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);
}
}

解决方案 »

  1.   

    就是这段程序会报一个Phone_Number.java 使用或覆盖了以过时的API  的错误,用什么方法来代替
    if("over".equalsIgnoreCase(new String(name,0,0,4)))
      

  2.   

    你用 java -Xlint Phone_Number.java 在编译一下
    是因为你出现了 new String(name, 0, 0, 4)
    API描述:
    String(byte[] ascii, int hibyte, int offset, int count) 
              已过时。 该方法无法将字节正确地转换为字符。从 JDK 1.1 开始,完成该转换的首选方法是使用带有 Charset、字符集名称,或使用平台默认字符集的 String 构造方法。
      

  3.   

    用这个
    String(byte[] bytes, int offset, int length, String charsetName) 
              通过使用指定的字符集解码指定的 byte 子数组,构造一个新的 String。
    用这个 new String(name, 0, 4, "utf16") 代替
      

  4.   

    可以运行了,但我怎么输入over程序不结束列
      

  5.   

    new String(name, 0, 4, "utf-16");
      

  6.   

    经过程序运行将if("over".equalsIgnoreCase(new String(name,0,0,4)))换成
    if("over".equalsIgnoreCase(new String(name,0,4,"ISO8859-1")))就OK了
      

  7.   

    但生成的phone.dat文件我用utraledit打开后发现,你把号码写前面,名字写后面了