我也遇到了这个问题,但在你的建议下没有解决。它仍然提示相同 错误:
正如我在
中看到的那样File contains a path separator.
问题原因:
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 cotains路径分隔符 在android.app.ContextImpl.makeFilename(ContextImpl.java:1682) 在android.app.ContextImpl.getFileStreamPath(ContextImpl.java:541)