JDK-4485313 : File protocol does not support output
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 1.4.0
  • Priority: P5
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2001-07-27
  • Updated: 2001-07-30
  • Resolved: 2001-07-30
Related Reports
Duplicate :  
Description

Name: bsC130419			Date: 07/27/2001


java version "1.4.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b65)
Java HotSpot(TM) Client VM (build 1.4.0-beta-b65, mixed mode)

An URLConnection supports output with the method getOutputStream. The API
documentation

says:

Throws:
IOException - if an I/O error occurs while creating the output stream.
UnknownServiceException - if the protocol does not support output

Unfortunately even an URLConnection to a file (of course with the file
protocol) does not

support output. This is a pity and because of this there is no generic way to
send output

to an URL (a file in an URL is not writable).

Also it makes no sense not to support output in this protocol. Of course if you
expect any

protocol to support output, it would be the file protocol.

URL url = new File("test.txt").toURL();
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
OutputStream output = connection.getOutputStream(); //throws an
UnknownServiceException

This bug is related to bug 1243005. The evalutation of that bug indeed mentions
that the file protocol does not support writing in the Java libraries. But if I
would expect any protocol to support output, it would be the file protocol.
(Review ID: 128950) 
======================================================================

Comments
EVALUATION See evaluation for 4191800
11-06-2004

WORK AROUND Name: bsC130419 Date: 07/27/2001 - Get the protocol from the URL - check if it is the file protocol - Extract the file from the URL - Open a FileOutputStream to the file. ======================================================================
11-06-2004