1. 写程序运行结果:
public class GetFilename {
private final char pathSeparator='\\';
/* 以下方法获取文件名,文件名是最后一个分隔符\后面的子串 */
public static String pickFile(String fullpath) {
int pos=fullpath.lastIndexOf(pathSeparator);
if (pos==-1) return fullpath;
return fullpath.substring(pos+1);
}
public static void main(String ags[]) {
String filename = pickFile("d:\\java\\example\\test.java");
System.out.println("filename="+ filename);
}
}