I asked a question here and I fixed my problem thanks to the user. This is the code I'm currently using.
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(); }
My goal is to upload the record_file.txt file to a specific web link, as you can see above. However, when I try to run this code, NetBeans gives me this error:
java.net.ProtocolException: cannot write to a URLConnection if doOutput=false - call setDoOutput(true)
I read some information about this, and I added the following code immediately after declaring this rbc variable.
URLConnection urlc = website.openConnection(); urlc.setDoOutput(true);
By the way, I always have the same error. could you help me?
source share