我只是在阅读一些java书籍并制作一些小程序进行练习,我创建了一个小代码来获取有关我输入的路径的信息,代码是:
String path = JOptionPane.showInputDialog("Enter Path to analyze");
File file = new File(path);
if (file.exists())
{
String result = "";
if (file.isDirectory())
{
result += "Path is directory\n ";
String [] resList = file.list();
for (String s : resList)
{
result += s + ", ";
}
}
if (file.isFile())
{
result += "Path is a file\n";
}
JOptionPane.showMessageDialog(null, result);
现在在输入对话框中,当我输入时C:
,结果是build, build.xml, manifest.mf, nbproject, src
,但是当我输入 C:/ 时,它显示了 C 中目录和文件的完整列表。
奇怪的是,D 驱动器和其他驱动器不会发生这种情况(即 D:/ 和 D: 的结果相同),请解释一下发生了什么?
更新 在使用 C# 的 WPF 中也会发生同样的情况!