Look at the methods of the String class. I think you can use the replace method since \n is an escape character. If not, you can do something like this:
int i = line.indexOf("\n");
line = line.subString(0, i); //may be i - 1
As far as your code is concerned, what is broken about it?