当前位置: 技术问答>java相关
在线等待!
来源: 互联网 发布时间:2015-04-09
本文导语: System.in.read() 读进来的是什么类型的?? 我这样行吗 String str=(String)System.in.read(); | //: Echo.java // How to read from standard input import java.io.*; public class Echo { public static void main(String[]...
System.in.read() 读进来的是什么类型的??
我这样行吗
String str=(String)System.in.read();
我这样行吗
String str=(String)System.in.read();
|
//: Echo.java
// How to read from standard input
import java.io.*;
public class Echo {
public static void main(String[] args) {
DataInputStream in =
new DataInputStream(
new BufferedInputStream(System.in));
String s;
try {
while((s = in.readLine()).length() != 0)
System.out.println(s);
// An empty line terminates the program
} catch(IOException e) {
e.printStackTrace();
}
}
} ///:~
// How to read from standard input
import java.io.*;
public class Echo {
public static void main(String[] args) {
DataInputStream in =
new DataInputStream(
new BufferedInputStream(System.in));
String s;
try {
while((s = in.readLine()).length() != 0)
System.out.println(s);
// An empty line terminates the program
} catch(IOException e) {
e.printStackTrace();
}
}
} ///:~
|
you should use
int read(byte[] b) (Reads some number of bytes from the input stream and stores them into the buffer array b. )
or wrap the System.in with StringBufferedInputStream
int read(byte[] b) (Reads some number of bytes from the input stream and stores them into the buffer array b. )
or wrap the System.in with StringBufferedInputStream
|
System.in是InputStream。
|
buxin
|
本来就应该是String类型
|
InputStream.read() returns int