SORU
28 EKİM 2012, Pazar


Java base64 kodlaması

Eclipse kullanıyorum. Aşağıdaki kod satırı var:

wr.write(new sun.misc.BASE64Encoder().encode(buf));

Eclipse hata olarak bu satırı işaretleyin. Gerekli kütüphaneleri import ediyorum;

import sun.misc.BASE64Encoder;
import sun.misc.BASE64Decoder;

Fakat yine de, her ikisi de hata olarak gösterilir. Benzer bir yazı buldum: import sun.misc.BASE64Encoder got error in Eclipse

Çözüm anlaşılacağı gibi Apache Commons yazarak kullandım

import org.apache.commons.*;

ve JAR dosyaları indirilen alma: http://commons.apache.org/codec/

Ama sorun hala var. Hataları daha önce de söylendiği gibi hatlarını gösteren tutulması. Lütfen yardımcı olun.

CEVAP
28 EKİM 2012, Pazar


Sınıfınızın alma değiştirmeniz gerekir.

muhtemelen böyle bir şey:

import org.apache.commons.codec.binary.Base64;

Ve sonra Sınıf BASE64 sınıfı kullanmak için değiştirin.

burada bazı örnek kod:

byte[] encodedBytes = Base64.encodeBase64("Test".getBytes());
System.out.println("encodedBytes "   new String(encodedBytes));
byte[] decodedBytes = Base64.decodeBase64(encodedBytes);
System.out.println("decodedBytes "   new String(decodedBytes));

O zaman why you shouldn't use sun.* packages okuyun.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • ★TheCrono Official Channel★

    ★TheCrono

    3 Mayıs 2014
  • DJPixcell

    DJPixcell

    20 NİSAN 2007
  • POGProductionz

    POGProductio

    27 NİSAN 2012