URL url = new URL(Config.local + "/excel/" + name); HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection(); // 设置请求信息 httpConnection.setRequestProperty("GET", "/down.zip HTTP/1.1"); // 设置接受信息 httpConnection.setRequestProperty("Accept", "image/gif,image/x-xbitmap,application/msword"); // 设置连接信息 httpConnection.setRequestProperty("Connection", "Keep-Alive"); // 获得输入流 InputStream input = httpConnection.getInputStream(); // 创建随机文件 flist.add(new File(name)); RandomAccessFile oSavedFile = new RandomAccessFile(name, "rw"); byte[] b = new byte[1024]; int nRead; // 从输入流中读入字节流,然后写到文件中 while ((nRead = input.read(b, 0, 1024)) > 0) { oSavedFile.write(b, 0, nRead); } input.close(); oSavedFile.close(); httpConnection.disconnect();
时间: 2024-10-28 10:28:16