?
Solved

new File returns false for canRead/canWrite for a shared directory

Posted on 2011-09-16
22
Medium Priority
?
291 Views
Last Modified: 2012-05-12
I am trying to open a shared directory on the network which is otherwise accessible from Windows but when I used JFileChooser and pass new File(directory).canRead and canWrite I always get a false back - anyone know why ?
0
Comment
Question by:abuyusuf35
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 8
  • 4
22 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 36551054

Are you sure you are running your application as the same user you are checking from windows ?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36551065
I assume you choose a directory with the JFileChooser? Can you post your code?
0
 

Author Comment

by:abuyusuf35
ID: 36551080
if (!new File(directory).canRead() && !new File(directory).canWrite())
{
      JOptionPane.showMessageDialog(this, " The location " + directory
        + " is not accessible ", "Message", JOptionPane.INFORMATION_MESSAGE);
      return;
}
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 47

Expert Comment

by:for_yan
ID: 36551095
maybe you need parentheses - embnbedded sapce there after new - will it work?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36551099
The code that gets 'directory' please
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36551115
No, parentheses do not matter I checked

But it also returned that I cannot read rtthe file which I in fact can read - the saem issue as you see
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36551120
>>maybe you need parentheses - embnbedded sapce there after new - will it work?

You don't need 'new' at all. Because the chooser should already be returning File
0
 

Author Comment

by:abuyusuf35
ID: 36551125
I am checking if the directory is accessible before I move it onto the JFileChooser - all other directories work fine but a shared one on the network doesn't for example \\shared_drive\myfiles

new File() itself returns false
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36551128
Please post the code i asked to see
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36551133
Actually, I was wrong - it works fine for me
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36551137
>>before I move it onto the JFileChooser

What does that mean? I guess i'll find out when you post the code...
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36551140
I think you cannot use UNC

try to map the drive to letter
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36551146
There are many limitations with UNC in windows - perhaps when you amp the dricve it will work
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36551147
If 'directory' is of type String then you'd need
File directory = new File("\\\\shared_drive\\myfiles");

Open in new window

0
 
LVL 47

Expert Comment

by:for_yan
ID: 36551152

There are many limitations with UNC in windows - perhaps when you map the drive it will work
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36551154
>>I think you cannot use UNC

You can (see above)
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36551157
But you are not typing them wexplicitly - you are taking them from Chooser ?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36551168
>>But you are not typing them wexplicitly - you are taking them from Chooser ?

If you think that, why are you commenting (incorrectly) about UNC?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36551224
>If you think that, why are you commenting (incorrectly) about UNC?
Those are different matters

But how can you be typing them iof you are getting file form the Chooser?

On some versions of windows systems there are limitations on UNC and it is underneath java
so if something cannot be explained it is better to try it with mapped drive
- I encountered that many times.

Are you saying that you mapped and it still is not workin?
0
 
LVL 47

Accepted Solution

by:
for_yan earned 2000 total points
ID: 36551269
And when you are network share domain authetication may be done in different way
When you map drive - it will check your crednetials at that moment

So then when you access file on the shared drive user was already authenticated.
Whereas with UNC it should happen at the moment when it reaches the file.

So especially when you see something which seems related to your privileges it is worth trying
to so it through mapping.

So I'm not "commenting (incorrectly)". I am suggesting the things to check.



0
 

Author Comment

by:abuyusuf35
ID: 36904274
I've requested that this question be closed as follows:

Accepted answer: 0 points for abuyusuf35's comment http:/Q_27312597.html#36551125

for the following reason:

None of the suggestions mentioned worked hence I went with my own solution
0
 

Author Comment

by:abuyusuf35
ID: 36904275
Will accept solution from one of the submitters
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month14 days, 3 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question