如果是读入Console的,请看这个:(Core Java的例子)public class Console
{
public static void printPrompt(String prompt)
{ System.out.print(prompt + " ");
System.out.flush();
}
/**
read a string from the console. The string is
terminated by a newline
@return the input string (without the newline)
*/
public static String readLine()
{ int ch;
String r = "";
boolean done = false;
while (!done)
{ try
{ ch = System.in.read();
if (ch < 0 || (char)ch == '\n')
done = true;
else if ((char)ch != '\r')
r = r + (char) ch;
}
catch(java.io.IOException e)
{ done = true;
}
}
return r;
}
/**
read a string from the console. The string is
terminated by a newline
@param prompt the prompt string to display
@return the input string (without the newline)
*/
public static String readLine(String prompt)
{ printPrompt(prompt);
return readLine();
}
}
{
public static void printPrompt(String prompt)
{ System.out.print(prompt + " ");
System.out.flush();
}
/**
read a string from the console. The string is
terminated by a newline
@return the input string (without the newline)
*/
public static String readLine()
{ int ch;
String r = "";
boolean done = false;
while (!done)
{ try
{ ch = System.in.read();
if (ch < 0 || (char)ch == '\n')
done = true;
else if ((char)ch != '\r')
r = r + (char) ch;
}
catch(java.io.IOException e)
{ done = true;
}
}
return r;
}
/**
read a string from the console. The string is
terminated by a newline
@param prompt the prompt string to display
@return the input string (without the newline)
*/
public static String readLine(String prompt)
{ printPrompt(prompt);
return readLine();
}
}
这是core java(java核心技术)那本书的作者自个写的
要买了那本书(或者到处找……)上的光盘才能copy到啊
并不是java自个带的
晕