Any suggestions on how to add a word or more using java to a text file to where if there is a sentence that ends with a period that the word is inserted before the period or if there is no period in the sentence, that it is just added to the sentence?

I'm thinking an if else statement might do the trick, but I am also wondering, would a substring also needed? And or any other suggestions?