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

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 ?
abuyusuf35Asked:
Who is Participating?
 
for_yanCommented:
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
 
for_yanCommented:

Are you sure you are running your application as the same user you are checking from windows ?
0
 
CEHJCommented:
I assume you choose a directory with the JFileChooser? Can you post your code?
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
abuyusuf35Author Commented:
if (!new File(directory).canRead() && !new File(directory).canWrite())
{
      JOptionPane.showMessageDialog(this, " The location " + directory
        + " is not accessible ", "Message", JOptionPane.INFORMATION_MESSAGE);
      return;
}
0
 
for_yanCommented:
maybe you need parentheses - embnbedded sapce there after new - will it work?
0
 
CEHJCommented:
The code that gets 'directory' please
0
 
for_yanCommented:
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
 
CEHJCommented:
>>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
 
abuyusuf35Author Commented:
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
 
CEHJCommented:
Please post the code i asked to see
0
 
for_yanCommented:
Actually, I was wrong - it works fine for me
0
 
CEHJCommented:
>>before I move it onto the JFileChooser

What does that mean? I guess i'll find out when you post the code...
0
 
for_yanCommented:
I think you cannot use UNC

try to map the drive to letter
0
 
for_yanCommented:
There are many limitations with UNC in windows - perhaps when you amp the dricve it will work
0
 
CEHJCommented:
If 'directory' is of type String then you'd need
File directory = new File("\\\\shared_drive\\myfiles");

Open in new window

0
 
for_yanCommented:

There are many limitations with UNC in windows - perhaps when you map the drive it will work
0
 
CEHJCommented:
>>I think you cannot use UNC

You can (see above)
0
 
for_yanCommented:
But you are not typing them wexplicitly - you are taking them from Chooser ?
0
 
CEHJCommented:
>>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
 
for_yanCommented:
>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
 
abuyusuf35Author Commented:
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
 
abuyusuf35Author Commented:
Will accept solution from one of the submitters
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.