title: Cannot write URLConnection because of doOutput
body: <p>I've asked a question here and I've fixed my problem thanks to an user. This is the code I am using at the moment.</p>
  
  <pre><code>void UploadToDatabase() throws MalformedURLException, IOException {
            URL website = new URL("http://mk7vrlist.altervista.org/databases/record_file.txt");
            WritableByteChannel rbc = Channels.newChannel(website.openConnection().getOutputStream());
  
            FileOutputStream fos;
            fos = new FileOutputStream("record_file.txt");
            fos.getChannel().transferTo(0, Long.MAX_VALUE, rbc);
            fos.close();
       }
  </code></pre>
  
  <p>My goal is upload the file <code>record_file.txt</code> on a particular web link as you can see above. However, when I try to run this code, NetBeans gives me this error:</p>
  
  <pre><code>java.net.ProtocolException: cannot write to a URLConnection if doOutput=false - call setDoOutput(true)
  </code></pre>
  
  <p>I read some stuff about this and I added the following code just after the declaration of that <code>rbc</code> variable.</p>
  
  <pre><code> URLConnection urlc = website.openConnection();
   urlc.setDoOutput(true);
  </code></pre>
  
  <p>By the way, I always have the same error. Could you help me?</p>