Using SMB protocol in URL while using JCIFS library on Android

mr_tawan picture mr_tawan · Jul 22, 2012 · Viewed 9.3k times · Source

I'm using JCIFS in my new Android project. Somehow I've decided to use URL class to generalized the file path (so I can add more protocol later). What I did is as below

URL url = new URL("smb://192.168.1.1/filepath");

And then java.net.MalformedURLException exception is thrown.

Exception in thread "main" java.net.MalformedURLException: unknown protocol: smb
    at java.net.URL.<init>(URL.java:184)
    at java.net.URL.<init>(URL.java:127)

Consulting JCIFS FAQ reveals that I have to register the protocol before using the class. However I don't really know how to do so in Android. I think the library do this already, but it doesn't on Android.

So what should I do ?

Answer

mr_tawan picture mr_tawan · Aug 5, 2012

I've just saw the usage in JCIFS reference, in the SmbFile reference.

When using the java.net.URL class with 'smb://' URLs it is necessary to first call the static jcifs.Config.registerSmbURLHandler(); method. This is required to register the SMB protocol handler.

So I add this call and it works properly.