Mapping an unknown drive in Java

I want to connect to a remote computer on the network that is NOT currently Drive mapped to my local computer.
I then want to copy a file from my local computer to the remote computer.
The code I have been trying to use is this:

      File fileTemp = new File(fileURI1);
      OutputStream out = new FileOutputStream(fileTemp);

I get the following exception \\USERID:PASSWORD@REMOTEHOSTNAME\SHARENAME\myfile.txt (The network path was not found)

WHat am I doing wrong?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

This isn't good news I'm afraid...

I tried to do something similar a number of months ago and came to the ultimate conclusion that it couldn't be done. In looking up the specification of the URI, it's not clear what's stated; it says file URIs are similar to FTP URIs, but no specific mention is made of usernames and passwords. I think it's legal URI syntax, but I don't think it's implemented in the JDK (although I couldn't confirm this in any other way other than the fact that it didn't work). I tried three different approaches; all failed. The only way I could get it to work (which I think you've hinted at already), is that if you map a drive to the remote location, it works - even if you use the full UNC path rather than the mapped drive. I guess Windows must automatically be passing the credentials.

Sorry that's of little help, but unless someone else can come up with an idea that works, at least it may save you additional effort. I wound up placing an FTP server on the target machine and just using FTP to access the file.

Open up My Computer and try doing the following,


Tell me what it says.

We had to do this for a project that required the monitoring of drop files on about 50 different workstations, all running
various windows versions, with the shared directories password protected.

We tried the solution you proposed and had little luck.
However, we were 100% successfull using
JCIFS to initiate the SMB share and pass in the user name/password.

Its a java based library available from:

Let me know if this helps!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It should solve your problems, and I forgot to mention the most important part ... it's open source and free.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

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.