[英]How to save a BLOB data type file on a device?
關於如何獲取保存在MySQL中的文件,然后將其保存在我的手機上的文件夾中的任何幫助。
我正在一個Android應用程序上工作,該應用程序在某個階段會從數據庫中選擇文件,這些文件存儲為BLOB ....然后我要將那些選擇的文件保存在我的設備上(Environment.getExternalStorageDirectory().getAbsolutePath()+ "/Testing/")
顯然我正在使用PHP將android連接到MySQL。 我該如何實現?
我認為,您應該首先將Blob轉換為Bitmap,然后將該Bitmap轉換為File,然后將此文件保存在外部存儲中。 例如,如果要從MySql數據庫獲取圖像:
Blob blob = // get Blob from MySql database
byte [] bytes = blob.getBytes(1, (int) blob.length());
Bitmap bmp = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
String filePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Testing/";
File dir = new File(filePath);
File file = new File(dir, "filename.png");
FileOutputStream fOut = new FileOutputStream(file);
bmp.compress(Bitmap.CompressFormat.PNG, 85, fOut);
fOut.flush();
fOut.close();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.