KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
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. 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 upload the file record_file.txt on a particular 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 stuff about this and I added the following code just after the declaration of that rbc variable. URLConnection urlc = website.openConnection(); urlc.setDoOutput(true); By the way, I always have the same error. Could you help me?
Tags (comma-separated)
Save Edits
Cancel