我正在尝试打开证书文件,在api 23以外的大多数android设备上都可以正常工作,在Internet上搜索发现我应该调用运行时权限,但是我没有成功,我将mkdir更改为getparentfile。 mkdir,没有用,请帮助,这是代码`public void copyfiles(Uri uri){
InputStream inputStream = null;
OutputStream outputStream = null;
try
{
ContentResolver content = getActivity().getContentResolver();
inputStream = content.openInputStream(uri);
File root = Environment.getExternalStorageDirectory();
if(root == null){
Log.d(TAG, "Failed to get root");
}
// create a directory
File saveDirectory = new File(Environment.getExternalStorageDirectory()+File.separator+ "/empresas/copy_" +File.separator);
// create directory if it doesn't exists
saveDirectory.getParentFile().mkdir();
//saveDirectory.mkdir();
//saveDirectory.mkdirs();
xfile = new File(saveDirectory+namefile);
xfile.getParentFile().mkdir();
outputStream = new FileOutputStream( saveDirectory+namefile); // filename.png, .mp3, .mp4 ...
if(outputStream != null){
Log.e( TAG, "Output Stream Opened successfully");
}
byte[] buffer = new byte[1000];
int bytesRead = 0;
while ( ( bytesRead = inputStream.read( buffer, 0, buffer.length ) ) >= 0 )
{
outputStream.write( buffer, 0, buffer.length );
}`
问题出现在outputStream上,我在日志中收到此错误:打开失败:EISDIR(是目录),谢谢您的帮助。