【发布时间】:2018-03-21 14:13:22
【问题描述】:
在java中我可以做到这一点
String sstream1 =
"as aasds 2 33\n" +
"this\n" +
"2.23\n";
InputStream stream = new ByteArrayInputStream(sstream1.getBytes());
Scanner cin = new Scanner(stream);
Scanner cin2 = new Scanner(sstream1);
String x1 = cin.next();
String x2 = cin.next();
int x3 = cin.nextInt();
int x4 = cin.nextInt();
String x5 = cin.next();
double x6 = cin.nextDouble();
Stream.of(x1, x2, x3, x4, x5, x6).forEach(o -> System.out.println(o));
x1 = cin2.next();
x2 = cin2.next();
x3 = cin2.nextInt();
x4 = cin2.nextInt();
x5 = cin2.next();
x6 = cin2.nextDouble();
Stream.of(x1, x2, x3, x4, x5, x6).forEach(o -> System.out.println(o));
我仍然得到相同的结果
as
aasds
2
33
this
2.23
as
aasds
2
33
this
2.23
所以我想知道使用这两种方法有什么区别,每种方法有什么优缺点,因为第二种方法更容易和简单,还有其他更好的方法可以实现吗?
【问题讨论】:
标签: java input stream inputstream