Hello everyone i am new to java and i have a problem. I accept a number with the String type, then I write it to the txt variable, then I overwrite it and add "\n", and then I try to convert it to the int type, but no matter what number is, it always turns out to be zero.
BufferedReader in = new BufferedReader(new InputStreamReader(clientConn.getInputStream()));
String txt = in.readLine();
txt = txt + "\n";
int number = Integer.parseInt(txt);
If I try to run a separate class that contains these lines of code, an error is thrown.
Exception in thread "main" java.lang.NumberFormatException: For input string: "1 "
and so with any number that I send.Always swears at the line int number = Integer.parseInt(txt);
.
Tell me how to solve this problem.