Why do we have to add forward slash in the file directory to differentiate between directory and files?
Inside the For loop:
Why do I have to add a forward slash after the directory name?
For example:
for(int i = 0; i<s.length; i++){
File f = new File(dirname + "/" + s[i] );
// Why to add "/" after dirname(i.e directory name)
if(f.isDirectory()){
System.out.println(s[i] + " is Directory" );
}else{
System.out.println(s[i] + " is File");
}
}
If I remove backslash "/" after dirname:
i.e In First Code
File f = new File(dirname + "/" + s[i] );
When I remove "/".
In the Second code:
File f = new File(dirname + s[i] );
It won't differentiate between Directory and File. All the Files inside will be considered to be the file.
After I add a backslash, it will be okay. And it will differentiate between Directory and File. Why is that?
Why do I have to add "/". The program is meant to look inside the file without adding "/".
java eclipse file directory backslash
add a comment |
Inside the For loop:
Why do I have to add a forward slash after the directory name?
For example:
for(int i = 0; i<s.length; i++){
File f = new File(dirname + "/" + s[i] );
// Why to add "/" after dirname(i.e directory name)
if(f.isDirectory()){
System.out.println(s[i] + " is Directory" );
}else{
System.out.println(s[i] + " is File");
}
}
If I remove backslash "/" after dirname:
i.e In First Code
File f = new File(dirname + "/" + s[i] );
When I remove "/".
In the Second code:
File f = new File(dirname + s[i] );
It won't differentiate between Directory and File. All the Files inside will be considered to be the file.
After I add a backslash, it will be okay. And it will differentiate between Directory and File. Why is that?
Why do I have to add "/". The program is meant to look inside the file without adding "/".
java eclipse file directory backslash
We can't say until we know what variables such ass
anddirname
are.
– Kilves
Jan 3 at 11:38
add a comment |
Inside the For loop:
Why do I have to add a forward slash after the directory name?
For example:
for(int i = 0; i<s.length; i++){
File f = new File(dirname + "/" + s[i] );
// Why to add "/" after dirname(i.e directory name)
if(f.isDirectory()){
System.out.println(s[i] + " is Directory" );
}else{
System.out.println(s[i] + " is File");
}
}
If I remove backslash "/" after dirname:
i.e In First Code
File f = new File(dirname + "/" + s[i] );
When I remove "/".
In the Second code:
File f = new File(dirname + s[i] );
It won't differentiate between Directory and File. All the Files inside will be considered to be the file.
After I add a backslash, it will be okay. And it will differentiate between Directory and File. Why is that?
Why do I have to add "/". The program is meant to look inside the file without adding "/".
java eclipse file directory backslash
Inside the For loop:
Why do I have to add a forward slash after the directory name?
For example:
for(int i = 0; i<s.length; i++){
File f = new File(dirname + "/" + s[i] );
// Why to add "/" after dirname(i.e directory name)
if(f.isDirectory()){
System.out.println(s[i] + " is Directory" );
}else{
System.out.println(s[i] + " is File");
}
}
If I remove backslash "/" after dirname:
i.e In First Code
File f = new File(dirname + "/" + s[i] );
When I remove "/".
In the Second code:
File f = new File(dirname + s[i] );
It won't differentiate between Directory and File. All the Files inside will be considered to be the file.
After I add a backslash, it will be okay. And it will differentiate between Directory and File. Why is that?
Why do I have to add "/". The program is meant to look inside the file without adding "/".
java eclipse file directory backslash
java eclipse file directory backslash
edited Jan 3 at 11:47
Andy Turner
84k983143
84k983143
asked Jan 3 at 11:35
sophinsophin
314
314
We can't say until we know what variables such ass
anddirname
are.
– Kilves
Jan 3 at 11:38
add a comment |
We can't say until we know what variables such ass
anddirname
are.
– Kilves
Jan 3 at 11:38
We can't say until we know what variables such as
s
and dirname
are.– Kilves
Jan 3 at 11:38
We can't say until we know what variables such as
s
and dirname
are.– Kilves
Jan 3 at 11:38
add a comment |
2 Answers
2
active
oldest
votes
Including and omitting the /
mean that the file points to a different path. For example, "foo/bar"
and "foobar"
are different paths, which would point to different objects in the file system:
Parent directory
+-- foobar "foobar"
+-- foo
+-- bar "foo/bar"
Not being a directory is not the same thing as being a file. So, most likely (we don't know what's in your file system), it's not a directory because it doesn't exist.
You should check if (!f.exists())
(or similar) first:
if (!f.exists()) System.out.println("Doesn't exist");
else if (f.isDirectory()) ... etc
Also, note that you shouldn't add a /
anyway - use the two-arg constructor:
File f = new File(dirname, s[i] );
Thanks for the answer. It really helped me!!
– sophin
Jan 6 at 4:46
add a comment |
Slash symbol is a file separator. This is used to separate the directories from the files.
If you are to build your string, the file name will be:
Pictures/my-dog.png
Here, you will see that there is a directory named "Picture" and a filename "my-dog.png".
If you were to remove the slash, it will look like a long filename:
Picturesmy-dog.png
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54021503%2fwhy-do-we-have-to-add-forward-slash-in-the-file-directory-to-differentiate-betwe%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Including and omitting the /
mean that the file points to a different path. For example, "foo/bar"
and "foobar"
are different paths, which would point to different objects in the file system:
Parent directory
+-- foobar "foobar"
+-- foo
+-- bar "foo/bar"
Not being a directory is not the same thing as being a file. So, most likely (we don't know what's in your file system), it's not a directory because it doesn't exist.
You should check if (!f.exists())
(or similar) first:
if (!f.exists()) System.out.println("Doesn't exist");
else if (f.isDirectory()) ... etc
Also, note that you shouldn't add a /
anyway - use the two-arg constructor:
File f = new File(dirname, s[i] );
Thanks for the answer. It really helped me!!
– sophin
Jan 6 at 4:46
add a comment |
Including and omitting the /
mean that the file points to a different path. For example, "foo/bar"
and "foobar"
are different paths, which would point to different objects in the file system:
Parent directory
+-- foobar "foobar"
+-- foo
+-- bar "foo/bar"
Not being a directory is not the same thing as being a file. So, most likely (we don't know what's in your file system), it's not a directory because it doesn't exist.
You should check if (!f.exists())
(or similar) first:
if (!f.exists()) System.out.println("Doesn't exist");
else if (f.isDirectory()) ... etc
Also, note that you shouldn't add a /
anyway - use the two-arg constructor:
File f = new File(dirname, s[i] );
Thanks for the answer. It really helped me!!
– sophin
Jan 6 at 4:46
add a comment |
Including and omitting the /
mean that the file points to a different path. For example, "foo/bar"
and "foobar"
are different paths, which would point to different objects in the file system:
Parent directory
+-- foobar "foobar"
+-- foo
+-- bar "foo/bar"
Not being a directory is not the same thing as being a file. So, most likely (we don't know what's in your file system), it's not a directory because it doesn't exist.
You should check if (!f.exists())
(or similar) first:
if (!f.exists()) System.out.println("Doesn't exist");
else if (f.isDirectory()) ... etc
Also, note that you shouldn't add a /
anyway - use the two-arg constructor:
File f = new File(dirname, s[i] );
Including and omitting the /
mean that the file points to a different path. For example, "foo/bar"
and "foobar"
are different paths, which would point to different objects in the file system:
Parent directory
+-- foobar "foobar"
+-- foo
+-- bar "foo/bar"
Not being a directory is not the same thing as being a file. So, most likely (we don't know what's in your file system), it's not a directory because it doesn't exist.
You should check if (!f.exists())
(or similar) first:
if (!f.exists()) System.out.println("Doesn't exist");
else if (f.isDirectory()) ... etc
Also, note that you shouldn't add a /
anyway - use the two-arg constructor:
File f = new File(dirname, s[i] );
answered Jan 3 at 11:44
Andy TurnerAndy Turner
84k983143
84k983143
Thanks for the answer. It really helped me!!
– sophin
Jan 6 at 4:46
add a comment |
Thanks for the answer. It really helped me!!
– sophin
Jan 6 at 4:46
Thanks for the answer. It really helped me!!
– sophin
Jan 6 at 4:46
Thanks for the answer. It really helped me!!
– sophin
Jan 6 at 4:46
add a comment |
Slash symbol is a file separator. This is used to separate the directories from the files.
If you are to build your string, the file name will be:
Pictures/my-dog.png
Here, you will see that there is a directory named "Picture" and a filename "my-dog.png".
If you were to remove the slash, it will look like a long filename:
Picturesmy-dog.png
add a comment |
Slash symbol is a file separator. This is used to separate the directories from the files.
If you are to build your string, the file name will be:
Pictures/my-dog.png
Here, you will see that there is a directory named "Picture" and a filename "my-dog.png".
If you were to remove the slash, it will look like a long filename:
Picturesmy-dog.png
add a comment |
Slash symbol is a file separator. This is used to separate the directories from the files.
If you are to build your string, the file name will be:
Pictures/my-dog.png
Here, you will see that there is a directory named "Picture" and a filename "my-dog.png".
If you were to remove the slash, it will look like a long filename:
Picturesmy-dog.png
Slash symbol is a file separator. This is used to separate the directories from the files.
If you are to build your string, the file name will be:
Pictures/my-dog.png
Here, you will see that there is a directory named "Picture" and a filename "my-dog.png".
If you were to remove the slash, it will look like a long filename:
Picturesmy-dog.png
answered Jan 3 at 12:31
KaNa0011KaNa0011
615615
615615
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54021503%2fwhy-do-we-have-to-add-forward-slash-in-the-file-directory-to-differentiate-betwe%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
We can't say until we know what variables such as
s
anddirname
are.– Kilves
Jan 3 at 11:38