Win a copy of liveProject: Protecting User Data with Spring Security and OAuth2 this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Directory not writable

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 6780
1297
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 26517
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 6780
1297
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 282
Eclipse IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 26517
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22144
115
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic