Java uri authority issue

I have a code snippet that I am having an issue with: I am attempting to access a file that is on a network share and requires authentication. I figured that I would use a URI to access this file. When I attempt to create the file using the uri I get the following error:

"File \Administrator:P@ssw0rd@192.168.0.222\share\tmp.txt exists? false
File not found: \Administrator:P@ssw0rd@192.168.0.222\share\tmp.txt (The filenae, directory name, or volume label syntax is incorrect)
Error: null"

I figure my problem is my password that contains an '@' I tried escaping with \\ but it does not seem to work. Does anyone have any ideas? Attached is the code snippet.
URI uri = null;
		try
		{
			String pass = "P@ssw0rd";
			uri=  new URI("file:///Administrator:" + pass + "@192.168.0.222/share/tmp.txt");
			
		}
		catch (Exception e)
		{
			System.out.println("URI Error: " + e.getMessage());
		}
		File f = new File(uri);
		System.out.println("File " + f.toString() + " exists? " + f.exists());

Open in new window

atxtechieAsked:
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.

objectsCommented:
that should be more like:

                        uri=  new URI("file://"+Administrator:" + URLEncoder.encode(pass, "UTF8") + "@192.168.0.222/share/tmp.txt");
0

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
CEHJCommented:
You can't do what you're attempting to do with the JDK. It doesn't support CIFS, which is central to Windows networking (assuming your example IS Windows). You need an API that does, like JCifs:

http://jcifs.samba.org/src/docs/api/jcifs/smb/SmbFile.html
0
atxtechieAuthor Commented:
I found a solution using staf
0
CEHJCommented:
I'm wondering then why you accepted that particular answer..?
0
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
Java

From novice to tech pro — start learning today.