Java 当字符串来自BLOB时,如何将字符串转换为byteArray?

Java 当字符串来自BLOB时,如何将字符串转换为byteArray?,java,android,Java,Android,我将一个BLOB从SQite转换为String,我想将该字符串转换为byteArray to,但不起作用。请帮帮我 在ArrayList HashMap上将BLOb转换为字符串: if (cursor.moveToFirst()) { do { HashMap<String, String> user = new HashMap<String, String>(); user.put("usernam

我将一个BLOB从SQite转换为String,我想将该字符串转换为byteArray to,但不起作用。请帮帮我

在ArrayList HashMap上将BLOb转换为字符串:

    if (cursor.moveToFirst()) {
        do {
            HashMap<String, String> user = new HashMap<String, String>();
            user.put("username" , cursor.getString(9));
            user.put("photo" , cursor.getBlob(10).toString());
            ImageList.add(user);
        } while (cursor.moveToNext());
    }
if(cursor.moveToFirst()){
做{
HashMap用户=新建HashMap();
user.put(“用户名”,cursor.getString(9));
user.put(“photo”,cursor.getBlob(10.toString());
ImageList.add(用户);
}while(cursor.moveToNext());
}
使用以下代码,我无法将上面得到的字符串转换为ByteArray,当我运行ImageView时,我什么也得不到:

    ArrayList<HashMap<String, String>> photoList;
    photoList = db.getString();
    HashMap<String, String> hashmap= photoList.get(0);

    String photo_name = hashmap.get("photo");
    byte[] byteArray = photo_name.getBytes();

    Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
    imageview.setImageBitmap(bmp);
ArrayList照片列表;
photoList=db.getString();
HashMap HashMap=photoList.get(0);
字符串photo_name=hashmap.get(“photo”);
byte[]byteArray=photo_name.getBytes();
位图bmp=BitmapFactory.decodeByteArray(byteArray,0,byteArray.length);
设置图像位图(bmp);

将字符串转换为字节数组的代码。

使用BLOB是一种反模式。您最好存储图像的路径并从存储中加载。@BernoulliGate,谢谢,但我不能使用路径,因为
sqlite
中的这个图像是我从mysql以base64的形式带来的,我将它存储到sqlite,现在我想以字符串的形式检索它,然后转换它
public class ConvertStringIntoBytes{

public void convertStringToByteArray() {
    String stringToConvert = "This is test string";
    byte[] theByteArray = stringToConvert.getBytes();
    System.out.println(theByteArray.length);
}

public static void main(String[] args) {
    new Main().convertStringToByteArray();
    }
}