遠程url文件地址轉成byte


public static byte[] urlTobyte(String url) throws MalformedURLException {  
    URL ur = new URL(url);
    BufferedInputStream in = null;  
    ByteArrayOutputStream out = null;  
    try {  
        in = new BufferedInputStream(ur.openStream());  
        out = new ByteArrayOutputStream(1024);  
        byte[] temp = new byte[1024];  
        int size = 0;  
        while ((size = in.read(temp)) != -1) {  
            out.write(temp, 0, size);  
        }  
    } catch (Exception e) {  
        e.printStackTrace();  
    } finally {  
        try {  
            in.close();  
        } catch (IOException e) {  
            e.printStackTrace();  
        }  
    }  
    byte[] content = out.toByteArray();  
    return content;  
} 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM