Reputation: 117
So I'm having issues with being able to save values using the method readLine() in bufferedReader, here is how my code is looking currently:
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();
}
What I want to achieve is to be able to use the value of inputLine twice. The problem I'm running into is no matter how I try to save it I call on in.readLine(), which when called on a second time is empty. Ideas?
Upvotes: 2
Views: 336
Reputation: 4065
Store the read value into a variable and reuse it any time you need it.
Use the usual pattern:
variable = readValue;
while (variable != null) {
// use the variable value any times
variable = readNextValue;
}
Upvotes: 2