Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Directory not writable  RSS feed

 
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
 
Java Cowboy
Sheriff
Posts: 16083
88
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
 
Marshal
Posts: 5923
875
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.
 
Sheriff
Posts: 23507
47
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
Marshal
Posts: 5923
875
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.
 
Ranch Hand
Posts: 278
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.
 
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: 23507
47
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?
 
Sheriff
Posts: 21330
87
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
Sheriff
Posts: 16083
88
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...
 
Happily living in the valley of the dried frogs with a few tiny ads.
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!