郎朗坤
请参阅以下测试程序:public class javatemp { static String stripExtension (String str) { // Handle null case specially. if (str == null) return null; // Get position of last '.'. int pos = str.lastIndexOf("."); // If there wasn't any '.' just return the string as is. if (pos == -1) return str; // Otherwise return the string, up to the dot. return str.substring(0, pos); } public static void main(String[] args) { System.out.println ("test.xml -> " + stripExtension ("test.xml")); System.out.println ("test.2.xml -> " + stripExtension ("test.2.xml")); System.out.println ("test -> " + stripExtension ("test")); System.out.println ("test. -> " + stripExtension ("test.")); }}输出:test.xml -> testtest.2.xml -> test.2test -> testtest. -> test