gpt4 book ai didi

java - 使用 StringReader 读取 String 的末尾

转载 作者:行者123 更新时间:2023-12-01 17:19:40 25 4
gpt4 key购买 nike

如何使用 Java 中的 StringReader 读取字符串的末尾,而我不知道字符串的长度是多少。

这是我到目前为止所取得的进展:

public static boolean portForward(Device dev, int localPort, int remotePort)
{
boolean success = false;
AdbCommand adbCmd = Adb.formAdbCommand(dev, "forward", "tcp:" + localPort, "tcp:" + remotePort);
StringReader reader = new StringReader(executeAdbCommand(adbCmd));
try
{
if (/*This is what's missing :/ */)
{
success = true;
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "There was an error while retrieving the list of devices.\n" + ex + "\nPlease report this error to the developer/s.", "Error Retrieving Devices", JOptionPane.ERROR_MESSAGE);
} finally {
reader.close();
}

return success;
}

最佳答案

String all = executeAdbCommand(adbCmd);
if (all.isEmpty()) {
}

通常 StringReader 用于分段读取/处理,并不适合这里。

BufferedReader reader = new BufferedReader(
new StringReader(executeAdbCommand(adbCmd)));
try
{ce
for (;;)
{
String line = reader.readLine();
if (line == null)
break;
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "...",
"Error Retrieving Devices", JOptionPane.ERROR_MESSAGE);
} finally {
reader.close();
}

关于java - 使用 StringReader 读取 String 的末尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19623693/

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