FileOutputStream保存文件

时间:2023-03-09 00:12:02
FileOutputStream保存文件
//保存文件,根据传入的路径,存放在SD卡目录下
public boolean saveToPath(String title, String pageName) { Bitmap b = getChartBitmap(); OutputStream stream = null;
try {
stream = new FileOutputStream(Environment.getExternalStorageDirectory().getPath()
+pageName+ "/" + title + ".png"); /*
* Write bitmap to file using JPEG or PNG and 40% quality hint for
* JPEG.
*/
b.compress(CompressFormat.PNG, 40, stream); stream.close();
} catch (Exception e) {
e.printStackTrace();
return false;
} return true;
}