?
Solved

Java uri authority issue

Posted on 2010-04-09
4
Medium Priority
?
461 Views
Last Modified: 2012-05-09
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

0
Comment
Question by:atxtechie
  • 2
4 Comments
 
LVL 92

Accepted Solution

by:
objects earned 375 total points
ID: 30250407
that should be more like:

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

Expert Comment

by:CEHJ
ID: 30313493
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
 

Author Closing Comment

by:atxtechie
ID: 32908046
I found a solution using staf
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 32908166
I'm wondering then why you accepted that particular answer..?
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses
Course of the Month3 days, 13 hours left to enroll

599 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