Jcifs.smb.smbexception: Access Is Denied. Exception For Smb Directories
In the below code statement: SmbFileInputStream din==new SmbFileInputStream(src); I am trying to create a SmbFileInputStream object. This will works fine if SmbFile 'src' is a fil
Solution 1:
You can't create an SmbFileInputStream
for a directory, because you can't read/write directly to the directory object. A directory doesn't have any content, at least not in the same way that a file has content.
If you're trying to read the contents of a directory, you should probably be using SmbFile
instead (for example, use the listFiles()
method). The SmbFileInputStream
object is only for reading information from a file.
To write a file to a directory, do this...
Filefile=newFile("/mnt/sdcard/filename.txt");
file.mkdirs(); // this creates all the directories that are missingFileOutputStreamos=newFileOutputStream (file);
// now write the file data
os.write(...);
In your code, change the following few lines...
try
{
din=newSmbFileInputStream(src);
dout=newFileOutputStream(Environment.getExternalStorageDirectory()+"/"+src.getName());
int c;
while((c=din.read())!=-1)
To this...
try
{
din=newSmbFileInputStream(src);
FileoutputFile=newFile(Environment.getExternalStorageDirectory()+"/"+src.getName()); // ADDED
outputFile.mkdirs(); // ADDED
dout=newFileOutputStream(outputFile); // CHANGEDint c;
while((c=din.read())!=-1)
Also change the following...
if(src.isFile()){
din=newSmbFileInputStream(src);
//dout=new FileOutputStream(Environment.getExternalStorageDirectory()+"/"+src.getName());// REMOVE THIS LINEFileoutputFile=newFile(Environment.getExternalStorageDirectory()+"/"+src.getName()); // ADDED
outputFile.mkdirs(); // ADDED
dout=newFileOutputStream(outputFile); // ADDED
}
else {
//din=new SmbFileInputStream(src); // REMOVE THIS LINEFileoutputFile=newFile(Environment.getExternalStorageDirectory()+"/"+src.getName());
outputFile.mkdirs();
//dout=new FileOutputStream(outputFile); // REMOVE THIS LINE
}
Post a Comment for "Jcifs.smb.smbexception: Access Is Denied. Exception For Smb Directories"