Your
main method is much much too long. Don't put all the logic in it; the ideal length of a main method is one statement.
Don't use multiple write instructions; that will risk slow execution. Use a StringBuilder or a StringJoiner to collect the text and write it all at once. A StringJoiner will obviate the need to
test whether you have reached the end of the series, and you can simply truncate a StringBuilder by 1 character.
Don't close your reader and writer explicitly; use
try with resources instead.
I also think you need separate reading and writing methods.
I wouldn't use a reader and Integer#parseInt; I would use a Scanner.
There is something wrong about your using a regular expression to trim the
String when you could use String#trim instead. In fact if you split on multiple whitespace
("\\s+"), you may not need to trim the String at all.
There seems to be a serious logic error in your method creating the List. Apart from the fact that the method doesn't look at all object‑oriented, you have a situation whereby you can return
null; I shall leave you to work out which circumstances will create a
null there. Line 44.