[問題] 寫檔案到伺服器上之文字檔
從伺服器上讀txt檔案是成功的
但不知道為什麼一樣的方法要把txt寫入伺服器上就是不行
程式碼:
URL url;
try {
url = new URL("http://XXX.xxx.xxx.xxx/XXX/data.txt");
URLConnection connection = url.openConnection();
OutputStream outStream = connection.getOutputStream();
BufferedWriter br = new BufferedWriter(new OutputStreamWriter(outStream));
br.write("test");
br.close();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
錯誤訊息在第五行
java.net.ProtocolException: cannot write to a URLConnection if doOutput=false
- call setDoOutput(true)
想請問這是怎麼一回事?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 180.218.236.86
推
07/19 20:37, , 1F
07/19 20:37, 1F
※ 編輯: gh8811211 來自: 180.218.236.86 (07/19 20:38)
→
07/19 20:38, , 2F
07/19 20:38, 2F
推
07/19 20:42, , 3F
07/19 20:42, 3F
→
07/19 20:43, , 4F
07/19 20:43, 4F
→
07/19 20:45, , 5F
07/19 20:45, 5F
→
07/19 20:46, , 6F
07/19 20:46, 6F
推
07/19 20:48, , 7F
07/19 20:48, 7F
→
07/19 20:49, , 8F
07/19 20:49, 8F
推
07/19 20:53, , 9F
07/19 20:53, 9F
→
07/19 21:02, , 10F
07/19 21:02, 10F
推
07/19 21:11, , 11F
07/19 21:11, 11F
→
07/19 21:20, , 12F
07/19 21:20, 12F
→
07/19 21:32, , 13F
07/19 21:32, 13F
推
07/19 21:43, , 14F
07/19 21:43, 14F
→
07/19 22:02, , 15F
07/19 22:02, 15F
→
07/19 22:03, , 16F
07/19 22:03, 16F
→
07/19 22:32, , 17F
07/19 22:32, 17F
→
07/19 23:16, , 18F
07/19 23:16, 18F
推
07/19 23:25, , 19F
07/19 23:25, 19F
→
07/19 23:27, , 20F
07/19 23:27, 20F
→
07/19 23:57, , 21F
07/19 23:57, 21F
推
07/20 01:51, , 22F
07/20 01:51, 22F
→
07/20 07:11, , 23F
07/20 07:11, 23F
→
07/20 15:18, , 24F
07/20 15:18, 24F
→
07/20 15:25, , 25F
07/20 15:25, 25F
推
07/20 16:01, , 26F
07/20 16:01, 26F
→
07/20 16:48, , 27F
07/20 16:48, 27F
→
07/20 20:35, , 28F
07/20 20:35, 28F
推
07/20 23:18, , 29F
07/20 23:18, 29F
推
07/20 23:20, , 30F
07/20 23:20, 30F
→
07/20 23:22, , 31F
07/20 23:22, 31F
推
07/20 23:25, , 32F
07/20 23:25, 32F
→
07/20 23:29, , 33F
07/20 23:29, 33F
推
07/20 23:42, , 34F
07/20 23:42, 34F
→
07/21 09:19, , 35F
07/21 09:19, 35F
→
07/22 00:18, , 36F
07/22 00:18, 36F
推
07/22 11:50, , 37F
07/22 11:50, 37F
推
07/22 11:52, , 38F
07/22 11:52, 38F
推
07/23 00:21, , 39F
07/23 00:21, 39F
推
07/23 00:49, , 40F
07/23 00:49, 40F
推
07/23 08:12, , 41F
07/23 08:12, 41F
推
07/23 08:14, , 42F
07/23 08:14, 42F
→
07/23 08:16, , 43F
07/23 08:16, 43F
推
07/23 10:53, , 44F
07/23 10:53, 44F
推
07/23 15:02, , 45F
07/23 15:02, 45F
→
07/23 15:04, , 46F
07/23 15:04, 46F
討論串 (同標題文章)
完整討論串 (本文為第 1 之 2 篇):
21
46
java 近期熱門文章
PTT數位生活區 即時熱門文章