Java接收 URL文件流 保存本地 DEMO

    xiaoxiao2021-03-25  63

    String  photoUrl="XXX";// HTTP请求返回文件流 Sting  fileTemp_path="/test/test.jsp";  //保存的文件流 // 此方法只能用户HTTP协议 URL url = new URL(photoUrl); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); DataInputStream in = new DataInputStream(connection.getInputStream()); DataOutputStream out = new DataOutputStream(new FileOutputStream( fileTemp_path));         buffer = new byte[65536]; int count = 0; while ((count = in.read(buffer)) > 0) { out.write(buffer, 0, count); } out.close(); in.close();
    转载请注明原文地址: https://ju.6miu.com/read-35875.html

    最新回复(0)