import java.io.*;
public class ConsoleInput{
public static String readLine(){
StringBuffer response=new StringBuffer();
try{
BufferedInputStream buff=new BufferedInputStream(System.in);
int in=0;
char inChar;
do{
in=buff.read();///////in是整数?输入的不是字母吗?
inChar=(char)in;///////////////////为什么把in转换成char?
if(in!=-1){
response.append(inChar);
}
}while((in!=-1)&(inChar!='\n'));
buff.close();
return response.toString();
}catch(IOException e){
System.out.println("Exception :"+e.getMessage());
return null;
}
}
public static void main(String[] args){
System.out.print("\nWhat is your name?");
String input=ConsoleInput.readLine();
System.out.println("\nHello ,"+input);
}
}
结果是
What is your name?yiyiHello , yiyi
public class ConsoleInput{
public static String readLine(){
StringBuffer response=new StringBuffer();
try{
BufferedInputStream buff=new BufferedInputStream(System.in);
int in=0;
char inChar;
do{
in=buff.read();///////in是整数?输入的不是字母吗?
inChar=(char)in;///////////////////为什么把in转换成char?
if(in!=-1){
response.append(inChar);
}
}while((in!=-1)&(inChar!='\n'));
buff.close();
return response.toString();
}catch(IOException e){
System.out.println("Exception :"+e.getMessage());
return null;
}
}
public static void main(String[] args){
System.out.print("\nWhat is your name?");
String input=ConsoleInput.readLine();
System.out.println("\nHello ,"+input);
}
}
结果是
What is your name?yiyiHello , yiyi
Reads the next byte of data from the input stream
也就是字节流,需要整理成你所需要的类型 例如
BufferedReader br = new BufferedReader(new InputStreamReader(ips));
String strWord = br.readLine();
throws IOExceptionReads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.
A subclass must provide an implementation of this method.
我想再问一下,字节是怎样记录字母的?是通过Unico码吗?
字节是什么?