Here you can find the source of getOutputStream(URL url)
static public OutputStream getOutputStream(URL url) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2007, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * //from w w w .j av a2s . c o m * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ import java.io.*; import java.net.URL; import java.net.URLConnection; public class Main { static public OutputStream getOutputStream(URL url) throws IOException { if (isFile(url)) { File file = new File(url.getPath()); if (!file.exists()) { File parent = file.getParentFile(); if (parent != null && !parent.exists()) parent.mkdirs(); } return new FileOutputStream(file); } // note that code below does not work for File URLs - "by design" Java // does not support creating output streams on file URLs. Code below should work // for HTTP URLs; no idea as to the other types of URLs URLConnection connection = url.openConnection(); connection.setDoOutput(true); return connection.getOutputStream(); } static public boolean isFile(URL url) { return ("file".equals(url.getProtocol())); //$NON-NLS-1$ } static public boolean exists(URL url) { if (isFile(url)) { File file = new File(url.getPath()); return file.exists(); } return true; } }