Im stuck with a problem regarding System.in.read(). I want to print everything that is pasted into the console. My code looks like this:
import java.io.IOException;
public class printer {
public static void main(String[ ] args) {
int i;
try {
while ((i = System.in.read()) != -1) {
char c = (char)i;
System.out.print(c);
}
}
catch (IOException e) {
e.printStackTrace();
}
}
}
The problem is that if you paste ,for example, three lines into the console the program will then print the two first lines, but not the third. Why is that? It prints the third if i press enter but with a huge space between the second and the third line.
I've also tried to store every char in a string and then print the whole string after the loop, but the loop never ends. Is their a way to stop this specific loop (I will not know how many rows the user will paste)