package com.wuziqi;
import java.io.*;
public class FileInput {
public static final int LENGTH = 100;
private static int readLine(byte line[]) throws IOException{
int i = 0;
int b = 0;
while(i<(LENGTH-1)&&(b=System.in.read())!='\n'){
line[i++]=(byte)b;
}//end while
return i;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
byte [] name = new byte[LENGTH];
byte [] phone = new byte [LENGTH];
int countName=-1;
int countNumber=-1;
boolean isExit = false;
FileWriter out;
String n = "";
String p = "";
try{
out = new FileWriter("notes");
while(!isExit){
System.out.println("Please enter the name:");
countName=readLine(name);
n = new String(name, 0, countName);
if("exit".equalsIgnoreCase(n)){
break;
}
System.out.println("Please enter the phone number:");
countNumber=readLine(phone);
p = new String(phone, 0, countNumber);
out.write(n);
out.write(':');
out.write(p);
out.write('\n');
out.flush();
}//end while
out.close();
}//end try
catch(FileNotFoundException e){
System.err.println(e);
}
catch(IOException e){
System.err.println(e);
}
}
}
为何输入 exit 后循环依然继续??求各位帮帮我这个新手。。。。