我使用了一个名为UploadFFGS
功能,这是它的内容:无法上传文件到服务器
URL url = new URL("http://linkedme.com/filebet.txt");
URLConnection ucn = url.openConnection();
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection = (HttpURLConnection) url.openConnection();
FileInputStream is = new FileInputStream("filebet.txt"); //before I download the same file because I must edit it and upload the new version
OutputStream ostream = connection.getOutputStream();
PrintWriter pwriter = new PrintWriter(ostream);
pwriter.print(jTextArea1.getText());
pwriter.close();
这个节目从来不是我的桌面上的文件filebet
我已经上传到我的链接(http://linkedme.com/filebet.txt
)。有任何想法吗?我把它用这种方式:
try {
UploadFFGS();
}
catch (MalformedURLException ex) {
Logger.getLogger(xGrep.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(xGrep.class.getName()).log(Level.SEVERE, null, ex);
}
此外,NetBeans的给了我这个错误: “java.net.ProtocolException:不能写入到一个URLConnection如果=则将DoOutput假 - 调用setDoOutput(真)”。
是否有某种异常或错误?当你在调试器中执行代码时,它在什么时候失败? – David
我不确定导致此功能的混淆。首先,你不能简单地写入一个URL。您需要确定本网站的文件上传规定 - 您是否必须通过某种形式发布文件?您也可以从URL中打开连接不少于三次,并且您的源文件的'FileInputStream'永远不会被读取。 –
我发布了错误+我使用的例外 –