81,092
社区成员
发帖
与我相关
我的任务
分享
String url = "http://aabb.com/12sf/xxoo/ab23.txt";
Matcher m = Pattern.compile(".*/(.*?.txt).*?").matcher(url);
while(m.find()){
System.out.println(m.group(1));
}
public class Hello {
public static void main(String[] args) throws IOException {
String url = "http://aabb.com/12sf/xxoo/ab23.txt";
String name = url.replaceAll(".*/(.*)$", "$1");
System.out.println(name);
}
}
public class GetFileName {
public static void main(String[] args) {
// TODO Auto-generated method stub
String s = "http://aabb.com/12sf/xxoo/ab23.txt";
String file = s.substring(s.lastIndexOf("/")+1);
System.out.println(file);
}
}
打印:
ab23.txt