Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在库中创建文件夹并保存文件_Android_File_Path_Copy - Fatal编程技术网

Android 如何在库中创建文件夹并保存文件

Android 如何在库中创建文件夹并保存文件,android,file,path,copy,Android,File,Path,Copy,现在我从外部存储文件夹复制mp4文件,并将复制文件保存在gallery with folder中。但我的gallery应用程序没有文件夹I代码。当然,我也是。但在文件浏览器中,DCIM文件夹中正确存在 那个么,我如何将文件保存在我编码的文件夹中的gallery中呢。如果你能解决这个问题,请告诉我 private void saveToGallery(String recVideoPath) { progressdialog = new CNetProgressdialog(this);

现在我从外部存储文件夹复制mp4文件,并将复制文件保存在gallery with folder中。但我的gallery应用程序没有文件夹I代码。当然,我也是。但在文件浏览器中,DCIM文件夹中正确存在

那个么,我如何将文件保存在我编码的文件夹中的gallery中呢。如果你能解决这个问题,请告诉我

private void saveToGallery(String recVideoPath) {
    progressdialog = new CNetProgressdialog(this);
    progressdialog.show();

    String folderName = "DuetStar";
    String fromPath = recVideoPath;
    String toPath = Environment.getExternalStorageDirectory() + "/" + Environment.DIRECTORY_DCIM;

    File toPathDir = new File(toPath + "/" + folderName);
    final File fromPathFile = new File(fromPath);
    File toPathFile = new File(toPath + "/" + folderName, recVideoPath.substring(recVideoPath.lastIndexOf("/") + 1, recVideoPath.length()));

    Log.d(TAG, "saveToGallery: " + RecordActivity.currentCreateFileName);
    Log.d(TAG, "saveToGallery: " + toPathDir.toString());
    Log.d(TAG, "saveToGallery: " + fromPath.toString());
    Log.d(TAG, "saveToGallery: " + toPath.toString());

    if (!toPathDir.exists()) {
        toPathDir.mkdir();
    } else {

    }

    FileInputStream fis = null;
    FileOutputStream fos = null;

    try {

        if (toPathDir.exists()) {
            fis = new FileInputStream(fromPathFile);
            fos = new FileOutputStream(toPathFile);

            byte[] byteArray = new byte[1024];
            int readInt = 0;

            while ((readInt = fis.read(byteArray)) > 0) {
                fos.write(byteArray, 0, readInt);
            }

            Log.d(TAG, "saveToGallery: " + readInt);

            fis.close();
            fos.close();

            Log.d(TAG, "saveToGallery: " + "Seucceful");
        } else {
            Toast.makeText(this, "There is no directory", Toast.LENGTH_SHORT).show();
        }
    } catch (IOException e) {
        e.getMessage();
    }

    progressdialog.dismiss();
}

您可以根据需要将idea的代码片段保存在特定文件夹中

字符串extStorageDirectory;
extStorageDirectory=Environment.getExternalStorageDirectory().toString()+“/Video Folder name/”;
//制作文件夹
新文件(extStorageDirectory).mkdirs();

我知道这一点。但它不起作用,因为在我的gallery应用程序中没有我需要的文件夹代码。但是谢谢你。