android: save images to specific folder in the sd card

后端 未结 3 1873
隐瞒了意图╮
隐瞒了意图╮ 2021-01-15 22:09

i have here a code snippet that saves a bitmap on sd card:

String filename = String.valueOf(System.currentTimeMillis()) ;
ContentValues values = new ContentV         


        
3条回答
  •  既然无缘
    2021-01-15 22:37

    Please try following code,

    File sdCard = Environment.getExternalStorageDirectory();
            File dir = new File (sdCard.getAbsolutePath());
            dir.mkdirs();
    
        File out = new File(dir,filename);
        try {
            out.createNewFile();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        DataOutputStream fo = null;
    
            try {
                fo = new DataOutputStream( new FileOutputStream(out));
                //write what you want to fo
                fo.close();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    

提交回复
热议问题