FileInputStream in = new FileInputStream(new File("D:/xx/a.txt")); URL url = new URL("http://ebook.ruanko.com/xxx/a.txt"); URLConnection connection = url.openConnection(); connection.setDoOutput(true); DataOutputStream ou = new DataOutputStream(connection.getOutputStream()); byte[] buffer = new byte[4096]; int count = 0; while ((count = in.read(buffer)) > 0) { ou.write(buffer, 0, count); } ou.flush(); ou.close(); in.close();
需求就是将本地磁盘d://xx/a.txt文件的内容写到远程WEB地址中的http://aaa.bbb.com WEB项目下的a.txt文件中,程序可以正常运行,带式就是内容没有写进去,不知道为什么?有遇到过类似问题的吗?