Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Mapping an unknown drive in Java

Posted on 2004-11-01
Medium Priority
Last Modified: 2010-05-18
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?
Question by:gnazzoj
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
  • 2

Expert Comment

ID: 12464278
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.


Expert Comment

ID: 12465093
Open up My Computer and try doing the following,


Tell me what it says.


Accepted Solution

sbrown2k earned 2000 total points
ID: 12470577
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!

Expert Comment

ID: 12470638
It should solve your problems, and I forgot to mention the most important part ... it's open source and free.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

610 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