【问题标题】:Not being able to store value from ReadLine (bufferedReader)无法从 ReadLine (bufferedReader) 存储值
【发布时间】:2019-01-30 22:42:13
【问题描述】:

所以我在使用 bufferedReader 中的 readLine() 方法保存值时遇到了问题,这是我的代码当前的样子:

            in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
            while((inputLine=in.readLine())!= null)
                try { g.doc.insertString(g.doc.getLength(), "\n" + new Xmlgetter(inputLine).outString, g.style); 
                }
                catch (BadLocationException e){
                    e.printStackTrace();
                }

我想要实现的是能够两次使用 inputLine 的值。我遇到的问题是无论我如何尝试保存它,我都会调用 in.readLine(),第二次调用它时它是空的。想法?

【问题讨论】:

    标签: java inputstream bufferedreader


    【解决方案1】:

    将读取的值存储到变量中,并在需要时随时重复使用。

    使用通常的模式:

    variable = readValue;
    while (variable != null) {
        // use the variable value any times
        variable = readNextValue;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-03-09
      • 2016-01-08
      • 2014-09-26
      • 2015-06-07
      • 2021-04-15
      • 1970-01-01
      相关资源
      最近更新 更多