JAVA讀取文件內容到byte[]數組

BufferedInputStream in = new BufferedInputStream(new FileInputStream("/media/music/hello.ogg"));        
                ByteArrayOutputStream out = new ByteArrayOutputStream(1024);        
    
                System.out.println("Available bytes:" + in.available());        
    
                byte[] temp = new byte[1024];        
                int size = 0;        
                while ((size = in.read(temp)) != -1) {        
                        out.write(temp, 0, size);        
                }        
                in.close();        
    
                byte[] content = out.toByteArray();        
                System.out.println("Readed bytes count:" + content.length);    
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章