java中如何获取文件名和路径?
我的目录中有一个 zip 文件,其名称会动态更改。 当我单击按钮时,我应该能够获取该文件的完整路径以及名称,如下所示:U:\home\ash\dfi\dfiZipedFile\dfi.zip
public static String getFileFullName(BcfiDownloadPanel bcfiDownloadPanel) {
File dir = new File("U:\\home\\ash\\dfi\\dfiZipedFile");
String[] filesList = dir.list();
if (filesList == null) {
// Either dir does not exist or is not a directory
} else {
for (int i = 0; i < filesList.length; i++) {
// Get filename of file or directory
String filename = filesList[i];
}
}
String fileFullName = filesList[0];
return fileFullName;
}
I have a zip file in a directory which his name dynamicaly changes.
when I click on a button I should be able to get full path of this file plus the name as follow: U:\home\ash\dfi\dfiZipedFile\dfi.zip
public static String getFileFullName(BcfiDownloadPanel bcfiDownloadPanel) {
File dir = new File("U:\\home\\ash\\dfi\\dfiZipedFile");
String[] filesList = dir.list();
if (filesList == null) {
// Either dir does not exist or is not a directory
} else {
for (int i = 0; i < filesList.length; i++) {
// Get filename of file or directory
String filename = filesList[i];
}
}
String fileFullName = filesList[0];
return fileFullName;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
类似于
返回目录中第一个文件的完整路径。
Something like
returns the full path of the first file in the directory.
如果这段代码能够工作,我会感到震惊。
您应该将文件名中的
\
替换为\\
。I would be stunned if this code would work.
you should replace the
\
with\\
in the filename.