How to get a binary file from a remote php script response?

后端 未结 1 1234
暗喜
暗喜 2021-01-26 10:17

I\'m calling a script that gives me a binary file (12345.cl), with binary data. The script is done, and it\'s working, if I paste it on the navigator I get the binary file.

相关标签:
1条回答
  • 2021-01-26 10:40

    You can use following code:

    public void decodeStream( String mURL, String ofile ) throws Exception {
        InputStream in = null;
        FileOutputStream out = null;
        try {
            URL url = new URL(mURL);
            URLConnection urlConn = url.openConnection();
            in = urlConn.getInputStream();
            out = new FileOutputStream(ofile);
            int c;
            byte[] b = new byte[1024];
            while ((c = in.read(b)) != -1)
                out.write(b, 0, c);
        } finally {
            if (in != null)
                in.close();
            if (out != null)
                out.close();
        }
    }
    
    0 讨论(0)
提交回复
热议问题