从路径中获取文件名

从路径中获取文件名

		String linuxStr = "/opt/netwatcher/pm4h2/work/data/msd/ORGDATA_6fcd818c_1546357389137_1.dat";
        String linuxPattern = "(.+)/(.+).dat$";

        Pattern r = Pattern.compile(linuxPattern);
        Matcher m = r.matcher(linuxStr);
        if (!m.find()) {
            System.out.println("文件路径格式错误!");
            return;
        }
        System.out.println(m.group(1));
        System.out.println(m.group(0));

        String windowStr = "F:\\work\\7DataQueryEngine\\1229\\ORGDATA_6fcd818c_1546357389137_1.dat";
        String windowPattern = "(.+)\\\\(.+).dat$";

        Pattern r1 = Pattern.compile(windowPattern);
        Matcher m1 = r1.matcher(windowStr);
        if (!m1.find()) {
            System.out.println("文件路径格式错误!");
            return;
        }
        System.out.println(m1.group(1));
        System.out.println(m1.group(0));

你可能感兴趣的:(java)