第1个回答 2014-01-23
如果知道该文件的路径filePath
可以用 String parentFilePath = filePath.subString(0,filePath.lastIndexOf("\\")) 获取当前文件夹所在的路径
然后 fileFolderName = parentFilePath.subString(parentFilePath.lastIndexOf("\\"),parentFilePath.length()); 获取文件夹的名称。
第2个回答 2014-01-23
String path ="F:\\tj_game\\log\\a.txt";
path=path.substring(0,path.lastIndexOf("\\"));
System.out.println("path"+path);
File file = new File(path);
String name = file.getName();
System.out.print(name);
第3个回答 2015-07-09
import java.io.File;
public class getFileName {
public static void main(String [] args)
{
String path ="C:\\Documents and Settings\\AllUsers\\Documents\\My Pictures";
File file = new File(path);
String name = file.getName();
System.out.print(name);
}
}
第4个回答 推荐于2016-11-22
使用
System.getProperty("user.dir")
即可
第5个回答 2014-01-23
以split(“\”),取返回的数组的倒数第二个!