• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Directory not writable

 
Vikram Gosain
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15216
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Vikram Gosain
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
ExamLab Creator
Marshal
Pie
Posts: 4328
238
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Clapham
Sheriff
Posts: 20983
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
ExamLab Creator
Marshal
Pie
Posts: 4328
238
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 277
Eclipse IDE Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
cchetan jain
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 20983
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15216
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic