Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7888743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:54:45+00:00 2026-06-03T05:54:45+00:00

In the below code statement: SmbFileInputStream din==new SmbFileInputStream(src); I am trying to create a

  • 0

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 file, but if ‘src’ is a smb Directory then it throws exception:

jcifs.smb.SmbException: Access is Denied.
at jcifs.smb.SmbTransport.checkStatus(SmbTransport.java:622)
at jcifs.smb.SmbTransport.send(SmbTransport.java:722)
at jcifs.smb.SmbSession.send(SmbSession.java:262)
at jcifs.smb.SmbTree.send(SmbTree.java:119)
at jcifs.smb.SmbFile.send(SmbFile.java:785)
at jcifs.smb.SmbFile.open0(SmbFile.java:1009)
at jcifs.smb.SmbFile.open(SmbFile.java:1026)
at jcifs.smb.SmbFileInputStream.<init>(SmbFileInputStream.java:73)
at jcifs.smb.SmbFileInputStream.<init>(SmbFileInputStream.java:65)
at testhelp.main(testhelp.java:25)

What is wrong with this code? or where am I going wrong?

Hi please check this code:

case DOWNLOAD2:

/*This code snippet is used to download a file/folder from smb nETWORK to android sd card.
when I run this code its throwing some exception. It have commented where ever necessary. rest of the code is self
explanatory. So please go through the code and please tell why this exception is thrown.
IF POSSIBLE PLEASE ADD A PROGRESS BAR WHICH SHOULD HELP USER SAYING SOME WORK IS GOING ON.
I have tried including a progress bar, but its not working. I ve read some materials related to this,
but every thing makes use threads. I am not that good at threads. So is it possible to include a progess bar,
without using threads?If possible please help me to do it.
And this code is working file for smb files, I dont know why its throwing exception in case of directories.
Please see why this is throwing exception..
So please see that the modified code contains:
a)no exceptions
b)a progress bar(more specifically a horizontal bar)*/

/*exception thrown:
jcifs.smb.SmbException: Access is Denied.
at jcifs.smb.SmbTransport.checkStatus(SmbTransport.java:622)
at jcifs.smb.SmbTransport.send(SmbTransport.java:722)
at jcifs.smb.SmbSession.send(SmbSession.java:262)
at jcifs.smb.SmbTree.send(SmbTree.java:119)
at jcifs.smb.SmbFile.send(SmbFile.java:785)
at jcifs.smb.SmbFile.open0(SmbFile.java:1009)
at jcifs.smb.SmbFile.open(SmbFile.java:1026)
at jcifs.smb.SmbFileInputStream.<init>(SmbFileInputStream.java:73)
at jcifs.smb.SmbFileInputStream.<init>(SmbFileInputStream.java:65)
at testhelp.main(testhelp.java:25)*/


StatFs statFs = new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath()); 
//if sd card is mounted then only this operation occur:
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
{
    //object.getCount() gets the number of objects in list view
    for(int i=0;i<object.getCount();i++)
    {
        //for each object in list view, if it is checked:
        if(object.getter(i)==true)
        {
            SmbFileInputStream din=null;
            FileOutputStream dout=null;
            try 
            {
                //I have used a hash table, which maps list view name with smb object
                SmbFile src=map.get(object.getItem(i));
                long blockSize = statFs.getBlockSize();
                long freeSize = statFs.getFreeBlocks()*blockSize;
                long diff=freeSize-src.length();
                boolean can=false;
                if(!(diff<0))
                {
                    can=true;
                }
                if(!src.isHidden() && can)
                {
                    try
                    {
                        if(src.isFile())
                        {
                            din=new SmbFileInputStream(src);
                            dout=new FileOutputStream(Environment.getExternalStorageDirectory()+"/"+src.getName());
                        }
                        else
                        {
                            din=new SmbFileInputStream(src);
                            File outputFile = new File(Environment.getExternalStorageDirectory()+"/"+src.getName()); // ADDED
                            outputFile.mkdirs(); // ADDED
                            dout=new FileOutputStream(outputFile); // CHANGED
                        }
                        int c;
                        while((c=din.read())!=-1)
                        {
                            dout.write(c);
                        }
                    }
                    finally
                    {
                        if (din != null) 
                        {
                            din.close();
                        }
                        if (dout != null) 
                        {
                            dout.close();
                        }
                    }
                }
                else
                {
                    Toast.makeText(this,src.getName()+" cannot be downloaded",Toast.LENGTH_LONG).show();
                }
            } 
            catch(IOException e)
            {
                Toast.makeText(this,"DOWNLOAD FAILED--IO EXCEPTION\n"+e,Toast.LENGTH_LONG).show();
            }
        }
    }
}
else
{
    Toast.makeText(this,"DOWNLOAD FAILED--NO SD CARD FOUND",Toast.LENGTH_LONG).show();
}
return true;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T05:54:46+00:00Added an answer on June 3, 2026 at 5:54 am

    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…

    File file = new File("/mnt/sdcard/filename.txt");
    file.mkdirs(); // this creates all the directories that are missing
    FileOutputStream os = new FileOutputStream (file);
    // now write the file data
    os.write(...);
    

    In your code, change the following few lines…

       try
       {
        din=new SmbFileInputStream(src);
        dout=new FileOutputStream(Environment.getExternalStorageDirectory()+"/"+src.getName());
        int c;
        while((c=din.read())!=-1)
    

    To this…

       try
       {
        din=new SmbFileInputStream(src);
    
        File outputFile = new File(Environment.getExternalStorageDirectory()+"/"+src.getName()); // ADDED
        outputFile.mkdirs(); // ADDED
    
        dout=new FileOutputStream(outputFile); // CHANGED
        int c;
        while((c=din.read())!=-1)
    

    Also change the following…

    if(src.isFile()){
        din=new SmbFileInputStream(src);
        //dout=new FileOutputStream(Environment.getExternalStorageDirectory()+"/"+src.getName());// REMOVE THIS LINE
        File outputFile = new File(Environment.getExternalStorageDirectory()+"/"+src.getName()); // ADDED
        outputFile.mkdirs();  // ADDED
        dout=new FileOutputStream(outputFile);  // ADDED
    }
    else {
        //din=new SmbFileInputStream(src); // REMOVE THIS LINE
        File outputFile = new File(Environment.getExternalStorageDirectory()+"/"+src.getName());
        outputFile.mkdirs(); 
        //dout=new FileOutputStream(outputFile); // REMOVE THIS LINE
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If statement works fine. It's code is shown below if (getInput1.getText() != null) {
How come I get this error when I'm declaring the code statement below? use
The below code works fine: ListControl lstMyControl; if (SomeVariable == SomeEnum.Value1) { lstMyControl =
This is the statement which I am referering the below code $.ajaxSetup ({ cache:
I am getting an compilation error not a statement for the below code. Not
When I use a conditional statement targeting IE6 and below with some PHP code
in the code below at first if statements block (there will be more than
Below code : URL oracle = new URL(http://www.oracle.com/); URLConnection inputStream =oracle.openConnection(); InputStream in =
I really want to get this out of my head. Please see below code:
I am trying out WebDriverBacked selenium. I used the below code. But, it gives

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.