Java string split with “.” (dot) [duplicate]
问题 This question already has an answer here: Split string with dot as delimiter 13 answers Why does the second line of this code throw ArrayIndexOutOfBoundsException ? String filename = \"D:/some folder/001.docx\"; String extensionRemoved = filename.split(\".\")[0]; While this works: String driveLetter = filename.split(\"/\")[0]; I use Java 7. 回答1: You need to escape the dot if you want to split on a literal dot: String extensionRemoved = filename.split("\\.")[0]; Otherwise you are splitting on