我尝试将字符串发送到我的InputStream:
String _source = "123";
InputStream in = new ByteArrayInputStream(_source.getBytes("UTF-8"));
tempLab2.readR(in);
String _source2 = "321";
in.read(_source2.getBytes());
_myClass.readR(in);
当我创建新的ByteArrayInputStream并将其设置_source为参数时,一切正常。我的方法 readR 不等待任何\n或EOFcharapters 并读取123.
请输入R:
回复:123
readR方法:
public void readR(InputStream inpSteram) {
Scanner tScanner = new Scanner(inpSteram);
System.out.println("Please enter R:");
_R = tScanner.nextDouble();
System.out.println("R: " + _R);
}
但是如果我发送所以我正在等待,我只_source2看到in.read(_source2.getBytes())Scanner
请输入R:
有任何想法吗?