Thank you for the reply. Please
always use the code button; it maintains indentation. I have edited your post so you can see how much easier it is to read.
I suspect your solution may not work, however. You will end up with an array full of the last value several times. There is however a simple way to correct that.
And please use System.err for printing Exception messages, not System.out.