• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 365
  • Last Modified:

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
java.io.FileNotFoundException: \\USERID:PASSWORD@REMOTEHOSTNAME\SHARENAME\myfile.txt (The network path was not found)

WHat am I doing wrong?
  • 2
1 Solution
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!
It should solve your problems, and I forgot to mention the most important part ... it's open source and free.
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.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now