[jcifs] canRead always returning false

Allen, Michael B (RSCH) Michael_B_Allen at ml.com
Thu Dec 13 17:50:14 EST 2001


I just tried a simple test and it worked ok for me. If the file exists I get true. But if the file does not exist I get false. I guess you don't get an SmbException because the boolean signature
suggests a boolean value should be returned. If something goofy happends then it will throw an SmbException (e.g AccessDenied).

import jcifs.smb.SmbFile;

public class CanRead {

        public static void main( String argv[] ) throws Exception {

                SmbFile f = new SmbFile( argv[0] );
                System.out.println( "" + f.canRead() );
        }
}

Mike

> -----Original Message-----
> From:	rjw [SMTP:rob at wygand.com]
> Sent:	Wednesday, December 12, 2001 10:52 PM
> To:	Allen, Michael B (RSCH)
> Cc:	'Rob Wygand'; jcifs at samba.org
> Subject:	Re: [jcifs] canRead always returning false
> 
> Yeah, false. I did some more poking, and saw it all the time when using 
> Samba as the file server, but it seemed okay using WinNT 4.0... so I'm 
> going to do some more debugging.
> 
> Noted on doing the op first, though that gave me some strange behavior. 
> For instance, the 1st time I tried to access a file I did not have 
> access to I got an Access Denied SmbException. The second time I tried, 
> the operation worked! Again, I have some more debugging to do here...
> 
> rjw
> 
> Allen, Michael B (RSCH) wrote:
> 
> > 
> >>-----Original Message-----
> >>From:	Rob Wygand [SMTP:rob at filefish.com]
> >>Sent:	Wednesday, December 12, 2001 7:46 PM
> >>To:	jcifs at samba.org
> >>Subject:	[jcifs] canRead always returning false
> >>
> >>Mike,
> >>
> >>Found something new today. It looks like SmbFile.canRead() is always 
> >>returning false.
> >>
> >>
> > 	False? That's very strange. From looking at the code I don't see how it's possible. It should return true if the file exists or throw an SmbException.
> > 
> > 
> >> I can subsequently make an SmbFileInputStream() from 
> >>the file, but I usually check canRead() first so that I can cleverly 
> >>show the user some nice error message.
> >>
> >>
> > 	You should just try and do the operation and then show the user the message associated with any exception that occurs. Calling canRead give you nothing and costs an extra round trip to the
> > server.
> > 
> > 
> >>Have you seen this?
> >>rjw
> >>
> >>
> >>
> > 
> 
> 
> -- 
> Robert J. Wygand, III, D.D.                  rob at wygand.com
> GPG  [A267 C8F7 34C2 2896 20F3]  [7DC8 2605 9E4C 573A 20EC]
> 
> "They that can give up essential liberty to obtain a little
>   temporary safety deserve neither liberty nor safety."
> 





More information about the jcifs mailing list