將byte數組寫入文件

public static void writeBytesToFile() throws IOException{
        String s = "aaaaaaaa";
        byte[] bs= s.getBytes();
        OutputStream out = new FileOutputStream("/storage/sdcard0/aaa");
        InputStream is = new ByteArrayInputStream(bs);
        byte[] buff = new byte[1024];
        int len = 0;
        while((len=is.read(buff))!=-1){
            out.write(buff, 0, len);
        }
        is.close();
        out.close();
    }

發佈了25 篇原創文章 · 獲贊 10 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章