【发布时间】:2019-07-15 04:00:17
【问题描述】:
我可以从输入流中读取第一行并将其存储到字符串变量中。然后我如何读取剩余的行并复制到另一个输入流以进一步处理。
InputStream is1=null;
BufferedReader reader = null;
String todecrypt = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
todecrypt = reader.readLine(); // this will read the first line
String line1=null;
while ((line1 = reader.readLine()) != null){ //loop will run from 2nd line
is1 = new ByteArrayInputStream(line1.getBytes());
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}
System.out.println("to decrpt str==="+todecrypt);
然后我将使用 is1 作为第二行的另一个输入流,并将我的示例文件发送到这里
【问题讨论】:
-
请提供一些您尝试过的代码
-
我发布了我尝试过的代码,你可以看看它。
-
从输入流中读取第一行后,您可以将其处理给其他人阅读。不需要新的
InputStream。 -
@jerry Chin 我可以使用相同的 inputStream 发送另一个类并从第二行再次读取吗?
标签: java spring inputstream