Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

java.net.UnknownServiceException: protocol doesn't support output

Status
Not open for further replies.

DeSn

Programmer
Nov 20, 2001
111
0
0
BE
Hi,

I recieve the following error : "java.net.UnknownServiceException: protocol doesn't support output" when I run the peace of code beneath.

Anyone?

authenticate("user", "pw");

URL destURL = new URL("file","max1","\\max1\public\test.txt");

buffedOut = new BufferedOutputStream(destURL.openConnection().getOutputStream());

 
URL.openConnection() returns an abstract class URLConnection. When you use the "file" protocol, the actual class that is returned for you is sun.net. This class overrides its parent class's (URLConnection) getOutputStream() so that output is not allowed on a file system object.

So in short, you cannot write to a file via a URL & URLConnection. You can however, read :

Code:
			URL url = new URL("file://\\java");
			URLConnection urlc = url.openConnection();
			System.err.println(urlc);
			BufferedReader br = new BufferedReader(new InputStreamReader(urlc.getInputStream()));
			String line = "";
			while ((line = br.readLine()) != null)
				System.err.println(line);

If you need to write, you will have to use a FileOutputStream or FileWriter/PrintWriter object.

--------------------------------------------------
Free Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top