gpt4 book ai didi

java - BufferedWriter在Android性能中的应用

转载 作者:行者123 更新时间:2023-12-02 04:58:13 26 4
gpt4 key购买 nike

我正在将数据写入 Android 中的文件(通过 BLE 接收)。

多次调用 BufferedWriter 之间是否存在性能差异,例如:

_writer.write(String.valueOf(sampleNumber));
_writer.write(",");
_writer.write(String.valueOf(characteristic.getIntValue(formatU8, 0)));
_writer.write(",");
_writer.write(String.valueOf(characteristic.getIntValue(formatU8, 1)));
_writer.write(",");

而不是构建一个 String,然后为每个收到的数据项调用 BufferedWriter 一次。

str1 = String.valueOf(_savedSampleCount) + "," + String.valueOf(characteristic.getIntValue(formatU8, 0)) + ","   + String.valueOf(characteristic.getIntValue(formatU8, 1)) + ",";

或者我应该使用 StringBuilder 代替?

最佳答案

您应该直接写入 BufferedWriter,就像您发布的代码一样。

buffering characters so as to provide for the efficient writing of single characters, arrays, and strings.

来自docs (强调我的)

关于java - BufferedWriter在Android性能中的应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28553476/

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