| Author |
Directory not writable
|
Vikram Gosain
Greenhorn
Joined: Jun 02, 2009
Posts: 25
|
|
Hi
In the code below I am getting "The directory is not writable" mesasge.But this directory is writable.I can very much create a file/folder/shortcut in this directory.
Can anyone please help me with this.?.
Thanks
-Vikz
|
-Vikz
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12956
|
|
Why are you mixing single slashes and double slashes in the directory name?
Windows works with a backslash \ as the path separator, not with a forward slash /. Because \ is an escape character in Java string literals, you have to use \\ in a Java string literal for a backslash. Try this:
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Vikram Gosain
Greenhorn
Joined: Jun 02, 2009
Posts: 25
|
|
Jesper Young wrote:Why are you mixing single slashes and double slashes in the directory name?
Windows works with a backslash \ as the path separator, not with a forward slash /. Because \ is an escape character in Java string literals, you have to use \\ in a Java string literal for a backslash. Try this:
Hello Jesper
I tried giving backslash the way you told me.I still did not work.You can try this small piece of code yourself on your system.
Thanks
-Vikz
|
 |
Devaka Cooray
Saloon Keeper
Joined: Jul 29, 2008
Posts: 2729
|
|
Are you sure that the given path, (including the "Quick Launch" sub-directory) already exists?
There may be another reason that you are using resources in "Documents and Settings" directory, which may require sufficient privileges to read/write them.
|
Author of ExamLab (Download) - the free mock exam kit for SCJP / OCPJP
HELP me! -- Home Page -- Twitter Profile -- JavaRanch FAQ -- How to Ask a Question
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16487
|
|
|
I think, if you do the experiment, you'll find that "canWrite()" returns false for every single directory in your file system. Try it and tell me if I'm wrong.
|
 |
Devaka Cooray
Saloon Keeper
Joined: Jul 29, 2008
Posts: 2729
|
|
Paul Clapham wrote:I think, if you do the experiment, you'll find that "canWrite()" returns false for every single directory in your file system. Try it and tell me if I'm wrong.
Mmm, that's not.
It returns true even for directories.
|
 |
Michael Angstadt
Ranch Hand
Joined: Jun 17, 2009
Posts: 272
|
|
Devaka Cooray wrote:Are you sure that the given path, (including the "Quick Launch" sub-directory) already exists?
Try using File.exists() to make sure your path is correct.
|
SCJP 6 || SCWCD 5
|
 |
cchetan jain
Ranch Hand
Joined: Jul 05, 2009
Posts: 30
|
|
|
hi..when this directory exists in the path,then canWrite() is true..and if this directory is not exists,it is simply can not be written obviously because after the instance creation of File object,the file is not created actually if the file is not exist.so canWrite() becomes false in this case..i tried it on my pc..
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16487
|
|
Devaka Cooray wrote:
Paul Clapham wrote:I think, if you do the experiment, you'll find that "canWrite()" returns false for every single directory in your file system. Try it and tell me if I'm wrong.
Mmm, that's not.
It returns true even for directories.
Okay. And when you did the experiment, did you notice anything the the directories with canWrite=false had in common?
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
Jesper Young wrote:Windows works with a backslash \ as the path separator, not with a forward slash /.
Actually, File knows how to handle forward slashes in Windows as well. That's why I prefer to use only forward slashes when creating relative File objects.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12956
|
|
If you really want to do it right, you should use File.separator instead of putting \ or / characters directly in your string:
But that's kind of long, and if the path starts with "C:", which is a Windows-only thing, it doesn't really make sense...
|
 |
 |
|
|
subject: Directory not writable
|
|
|