相关疑难解决方法(0)

在Android中存储SD卡上的数据

使用文档中数据存储页面,我试图将一些数据存储到SD卡中.这是我的代码:

    // Path to write files to
    String path = Environment.getExternalStorageDirectory().getAbsolutePath() +
                  "/Android/data/"+ctxt.getString(R.string.package_name)+"/files/";
    String fname = "mytest.txt";

    // Current state of the external media
    String extState = Environment.getExternalStorageState();

    // External media can be written onto
    if (extState.equals(Environment.MEDIA_MOUNTED))
    {
        try {
            // Make sure the path exists
            boolean exists = (new File(path)).exists();  
            if (!exists){ new File(path).mkdirs(); }  

            // Open output stream
            FileOutputStream fOut = new FileOutputStream(path + fname);

            fOut.write("Test".getBytes());

            // Close output stream
            fOut.flush();
            fOut.close();

        } catch …
Run Code Online (Sandbox Code Playgroud)

android sd-card

7
推荐指数
1
解决办法
8148
查看次数

标签 统计

android ×1

sd-card ×1