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(); }