Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.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 java.lang.IllegalArgumentException:File/data/epay/share/Download/test280.mp4包含一个路径分隔符_Android_File - Fatal编程技术网

Android java.lang.IllegalArgumentException:File/data/epay/share/Download/test280.mp4包含一个路径分隔符

Android java.lang.IllegalArgumentException:File/data/epay/share/Download/test280.mp4包含一个路径分隔符,android,file,Android,File,我也发现了这个问题,但没有在你的建议下解决。还是一样 错误: 正如我在书中看到的那样 问题的原因是: if (isValidMediaFile && (dir != null) ) { boolean bFile = dir.exists(); Log.i(TAG,"file flag " + bFile); if(!bFile){ dir.mkdirs(); //Runtime.getRuntime().exec("cp

我也发现了这个问题,但没有在你的建议下解决。还是一样 错误:

正如我在书中看到的那样

问题的原因是:

if (isValidMediaFile && (dir != null) ) {
    boolean bFile = dir.exists();
    Log.i(TAG,"file flag " + bFile);
    if(!bFile){
        dir.mkdirs();
        //Runtime.getRuntime().exec("cp " + f + " " + f);
    }
    Log.i(TAG, "dir= " + dir.getPath());
    try {
        String file = 
                srcfile.substring(srcfile.lastIndexOf("/")+1, 
                        srcfile.length());
        File dstfile = new File(
                dir.getAbsolutePath() + "/" + file);
        Log.i(TAG, "dst =" + dstfile);
        if(!dstfile.exists()){
            dstfile.createNewFile();
        }
        //copyFile(srcfile, dstfile);
        //FileInputStream in = context.openFileInput(srcfile);

        File sfile = context.getFileStreamPath(srcfile);
        FileInputStream in = new FileInputStream(sfile);

        BufferedInputStream bi =  new BufferedInputStream(in);

        FileOutputStream out = context.openFileOutput(dstfile.getName(), 
                Context.MODE_PRIVATE);
        BufferedOutputStream bo = new BufferedOutputStream(out);

        byte[] b = new byte[8192];
        int len;
        while( (len = bi.read(b))!= -1) {
            bo.write(b, 0,len);
        }
        out.flush();

        bi.close();
        bo.close();
        in.close();
        out.close();                    
    } catch (IOException e) {
        // TODO: handle exception
        e.printStackTrace();
    }               
}
日志消息为: java.lang.IllegalArgumentException:File/data/epay/share/Download/test280.mp4包含一个路径分隔符 在android.app.ContextImpl.makeFilename(ContextImpl.java:1682)中
在android.app.ContextImpl.getFileStreamPath(ContextImpl.java:541)

我只想将一个文件从/data/epay/share/Download/test280.mp4从手机内存复制到sdcard文件夹,格式为/mnt/sdcard/video,“日志消息是…”应该是“日志消息是…”很抱歉用自然语言检查我的语法错误。您可以使用FileUtils.copyFile(File srcFile,File destFile)从新文件(“/data/epay/share/Download/test280.mp4”);并且我没有FileUtils包,我确实使用copyFile(File srcFile,File dstfile),因此可以自行实现。您需要下载