当前位置: 技术问答>java相关
帮看看我这断代码!有分奖励!
来源: 互联网 发布时间:2015-10-02
本文导语: import java.io.*; class InputStreamReaderExample { public static void main(String[] args) { System.out.println("Type a line of text. Type 'exit' to quit the program."); InputStreamReader in=new InputStreamReader(System.in); BufferedReader reader=new ...
import java.io.*;
class InputStreamReaderExample {
public static void main(String[] args) {
System.out.println("Type a line of text. Type 'exit' to quit the program.");
InputStreamReader in=new InputStreamReader(System.in);
BufferedReader reader=new BufferedReader(in);
String data=null;
try {
while((data=reader.readLine()).indexOf("exit")==-1) {
System.out.print("The line you typed was: ");
System.out.println(data);
}
}
catch(IOException ex) {
System.out.println(ex);
}
}
}
我想知道为什么我把BufferedReader reader=new BufferedReader(in);拿掉再把while((data=reader.readLine()).indexOf("exit")==-1) 里面的reader改成in
就编译不过了。请高手指教!
class InputStreamReaderExample {
public static void main(String[] args) {
System.out.println("Type a line of text. Type 'exit' to quit the program.");
InputStreamReader in=new InputStreamReader(System.in);
BufferedReader reader=new BufferedReader(in);
String data=null;
try {
while((data=reader.readLine()).indexOf("exit")==-1) {
System.out.print("The line you typed was: ");
System.out.println(data);
}
}
catch(IOException ex) {
System.out.println(ex);
}
}
}
我想知道为什么我把BufferedReader reader=new BufferedReader(in);拿掉再把while((data=reader.readLine()).indexOf("exit")==-1) 里面的reader改成in
就编译不过了。请高手指教!
|
因为,InputStreamReader没有readLine()方法