Android 存储 内部存储
给出关键代码
public void save(View view) throws IOException { AssetManager manager = getAssets(); InputStream is = manager.open("logo.png"); FileOutputStream fos = openFileOutput("logo.png", Context.MODE_PRIVATE); byte[] buffer = new byte[1024]; int len = -1; while((len = is.read(buffer))!=-1){ fos.write(buffer,0,len); } fos.close(); is.close(); Toast.makeText(this,"保存完成",Toast.LENGTH_LONG).show(); } public void read(View view) { String filePath = getFilesDir().getAbsolutePath(); String imgPath = filePath+"/logo.png"; Bitmap bitmap = BitmapFactory.decodeFile(imgPath); iv_if.setImageBitmap(bitmap); }
AssetManager manager = getAssets();
InputStream is = manager.open("logo.png"); //这里打开的是Assets下的文件
FileOutputStream fos = openFileOutput("logo.png", Context.MODE_PRIVATE); //这里完整路径 /data/user/0/com.example.storage/files/logo.png
String filePath = getFilesDir().getAbsolutePath(); //这里完整路径 /data/user/0/com.example.storage/files/