def LocalFileToURL(localFileName):
    "Convert a filename to an XPCOM nsIFileURL object."
    # Create an nsILocalFile
    localFile = components.classes["@mozilla.org/file/local;1"] \
          .createInstance(components.interfaces.nsILocalFile)
    localFile.initWithPath(localFileName)

    # Use the IO Service to create the interface, then QI for a FileURL
    io_service = components.classes["@mozilla.org/network/io-service;1"] \
                    .getService(components.interfaces.nsIIOService)
    url = io_service.newFileURI(localFile).queryInterface(components.interfaces.nsIFileURL)
    # Setting the "file" attribute causes initialization...
    url.file = localFile
    return url