gpt4 book ai didi

java - 创建流而不是临时文件并使用它们并丢弃它们

转载 作者:太空宇宙 更新时间:2023-11-04 08:11:01 25 4
gpt4 key购买 nike

我想写入流并立即使用它,而不是写入文件并读取。文件不是线程安全的,我认为这可能会影响性能。

    //set property to an existing file
prop.setProperty("$quoteValidity",""no");
prop.setProperty("$date", "today");
prop.setProperty("$quantitySum", Integer.toString(quantitySum));

//store it in temporary location
prop.store(new FileOutputStream("<Temp file location>"), null);

//open that temp file as stream
InputStream propfile = new FileInputStream("<Temp file location>");

List<Order> orderList = XmlToList.makeOrderFromNodeList(orderNode);
//use that temp file
Testground.generateXlsx(propfile,orderList);

最佳答案

尝试使用 ByteArrayOutputStream 而不是 FileOuputStream。然后您可以调用

 byte[] bytes=byteArrayOutputStream.toByteArray() 

在 ByteArrayOutputStream 上获取字节

然后构造一个 ByteArrayInputStream(bytes) 并将其传递到 Testground

关于java - 创建流而不是临时文件并使用它们并丢弃它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11227755/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com