您的位置:首页 > 编程语言 > Java开发

java中通过文件路径获取文件名

2015-12-30 15:46 579 查看
import java.io.File;

public class Test

{
public static void main(String[] args)
{
// path
String path1 = "D:/folder1/folder2/folder3/fileName.txt";
String path2 = "/folder2/folder3/fileName.txt";
// file
File file1 = new File(path1);
File file2 = new File(path2);
// get name of file
String fileName1 = file1.getName();
String fileName2 = file2.getName();
// print file name
System.out.println("1 ---> " + fileName1);
System.out.println("2 ---> " + fileName2);
}
}

//1 ---> fileName.txt

//2 ---> fileName.txt

转载自:http://blog.csdn.net/aotian16/article/details/5790404
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: