2016-04-12 17 views
5

Bir base64 dizgisini çözmek ve bir dosyaya (pdf/jpg olarak) dönüştürmek ve cihaza kaydetmek istiyorum. (/storage/emulated/0/Download/file.pdf). ... ben bu base64 dize deocde ve bir dosya haline dönüştürmek ve cihazda kaydetmek istiyorum, ŞimdiBase64 dizgisini nasıl çözebiliriz ve pdf/jpg'ye dönüştürün ve depoya kaydedin

kutu

File originalFile = new File("/mnt/sdcard/download/file.pdf"); 
    String encodedBase64 = null; 
    try { 
     FileInputStream fileInputStreamReader = new FileInputStream(originalFile); 
     byte[] bytes = new byte[(int) originalFile.length()]; 
     fileInputStreamReader.read(bytes); 
     encodedBase64=Base64.encodeToString(bytes,Base64.NO_WRAP); 
     messaggio=encodedBase64.toString(); 
     //encodedBase64 = new String(Base64.encode(bytes)); 
    } catch (FileNotFoundException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 

:

kodlamasının için bir dosya ben bu kodu kullanın biri bana yardım etsin?

cevap

10

Bu deneyebilirsiniz) = hepinize teşekkür:

FileOutputStream fos = new FileOutputStream(filepath); 
fos.write(Base64.decode(base64String, Base64.NO_WRAP)); 
fos.close(); 

Nerede: Yeni dosyada

  • filepath: Yol
  • base64String: istediğiniz Sizin base64 dize dönüştürmek
İlgili konular