I'm trying to get text entered by a user, but there seems to be a limit on the number of characters that a user can type in. I'm using BufferedReader
to read from System.in
and this is what I had for my code originally:
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter text.");
while (true){
System.out.print("Text> ");
String line = r.readLine();
if (line == null || line.equalsIgnoreCase("q")) {
break;
}
else {
System.out.println("Response: " + line);
System.out.println("Response length: " + line.length());
}
}
This is what I get when I run it with some sample text:
Text> WASHINGTON — Republicans on Thursday vowed a swift and forceful response to the executive action on immigration that President Obama is to announce in a prime-time address, accusing the president of exceeding the power of his office and promising a legislative fight when they take full control of Congress next year. Senator Mitch McConnell of Kentucky, who will become majority leader in January, said in a speech on the Senate floor Thursday morning that Mr. Obama would regret choosing to ignore the wishes of the American people. “If President Obama acts in defiance of the people and imposes his will on the country, Congress will act,” Mr. McConnell said just hours before the president was scheduled to speak to the nation on television. “We’re considering a variety of options. But make no mistake. Make no mistake. When the newly elected representatives of the people take their seats, they will act.” Mr. McConnell did not say what options Republicans were considering, but the party is sharply di
Response: WASHINGTON — Republicans on Thursday vowed a swift and forceful response to the executive action on immigration that President Obama is to announce in a prime-time address, accusing the president of exceeding the power of his office and promising a legislative fight when they take full control of Congress next year. Senator Mitch McConnell of Kentucky, who will become majority leader in January, said in a speech on the Senate floor Thursday morning that Mr. Obama would regret choosing to ignore the wishes of the American people. “If President Obama acts in defiance of the people and imposes his will on the country, Congress will act,” Mr. McConnell said just hours before the president was scheduled to speak to the nation on television. “We’re considering a variety of options. But make no mistake. Make no mistake. When the newly elected representatives of the people take their seats, they will act.” Mr. McConnell did not say what options Republicans were considering, but the party is sharply di
Response length: 1011
Text>
No matter howlong the text is, it always gets cut off at the 1011th character. (It actully gets cut off at the 1012th character, but I have to delete that character in order to press the ENTER key to insert a newline.)
I thought the problem was somewhere in BufferedReader's readLine()
method, so I tried using the read()
and read(char[] cbuf, int off, int len)
methods also from BufferedReader, but I still couldn't enter more than 1011 characters. The same problem still happens when I use Scanner
instead of BufferedReader
.
I then came to the conclusion that it just had something to do with my system, so I tried running the same code on a different server and found that I could enter up to 4049 characters that time (excluding the newline character at the end).
Does anyone know why this is, and what I can change such that I can read more characters through System.in
? I can post more of my code if necessary.