gpt4 book ai didi

java - 将字符串数组写入文件 - 一行?

转载 作者:太空宇宙 更新时间:2023-11-04 06:54:40 26 4
gpt4 key购买 nike

这是一个示例,我从文件中读取行作为字符串,以使整个文件作为字符串数组:

String[] ArrayOfStrings = (new Scanner( new File("log.txt") ).useDelimiter("\\A").next()).split("[\\r\\n]+");

我有任何类似的方法可以将其写回到文件中:

something_that_writes_into_file(ArrayOfStrings)?

我了解 PrintWriterBuffer 和其他使用循环的东西。

我的问题具体是关于更紧凑的东西,例如 - 一行解决方案?

最佳答案

使用Apache Commons IOApache StringUtils :

FileUtils.writeStringToFile(new File(theFile), StringUtils.join(theArray, delimiter));

关于java - 将字符串数组写入文件 - 一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22912009/

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