比如有一个文件的路径
d:\abc\def\g.txt用什么程序得到这个结果呢?也就是说在路径后去掉文件名的后缀。
d:\abc\def\g麻烦解答一下下~~~

解决方案 »

  1.   

    str.subString(0, str.lastIndexOf("."));
      

  2.   

    public class FileName {
    public static void main(String[] args) {
    File f = new File("c:\\test.txt");
    String path = f.getPath();
    System.out.println(path.substring(0,path.lastIndexOf(".")));
    }
    }
      

  3.   

    这么简单就不用正则表达式了吧。。我汗string.lastindexof("\")string.substring();
      

  4.   

    错了,晕string.lastindexof(".")string.substring();