问题描述
我刚刚阅读了一些java书并制作了一些小程序用于练习,我创建了一个小代码来获取有关我输入的路径的信息,代码是:
I was just reading some java book and making some small programs for practice, I created a small code to get information about the path I entered, and the code is:
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中的文件。
Now in the input dialogue, when I enter C:
, the result is build, build.xml, manifest.mf, nbproject, src
, but when I enter C:/, it shows the complete list of directories and files in C.
奇怪的是,D驱动器和其他驱动器不会发生这种情况(即D:/和D :)结果相同,发生了什么请解释一下?
And strangely it does not happen with the D drive and other drives (i.e. the result is same for D:/ and D:), what is happening please explain?
更新
使用C#在WPF中也是如此!
UpdateSame happens in WPF using C#!
推荐答案
C:
表示当前在驱动器上选择的目录 C:
。在您的情况下,它可能是您的应用程序运行的目录。
C:
means "whatever directory is currently selected on drive C:
". In your case, it's probably the directory that your application is running from.
D:
与 D:/
在您的情况下,因为根目录 中的当前工作目录D:
。
D:
is the same as D:/
in your case because the root directory is the current working directory in D:
.
这篇关于C:和C之间的区别:/的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!