jcifs.smb
Class SmbFile

java.lang.Object
  |
  +--jcifs.smb.SmbFile

public class SmbFile
extends Object

This class represents a file or directory on an SMB file server. All methods should operate identically to those of the File class. One fundamental difference is the usage of a URL to specify the location of a file or diectory. All SmbFile URLs have the following syntax:

smb://[[domain;]username[:password]@]hostname[:port]/share[/path]
Examples:
 smb://users-nyc;msmith:PaSsW#Rd@storage15/docs/oct/YahooEarnings887.doc
 smb://Administrator:Fo0BarP@ss@msmith1/c/WINDOWS/Desktop/YHOO Reports.txt
 smb://storage15/public
 
If may also be necessary to specify properties for jcifs to function correctly. See Setting JCIFS Properties for details.

A second constructor argument may be specified to augment the URL for better programmatic control when processing many files under a common base. This is slightly different from the corresponding java.io.File usage as '/' at the beginning of the second parameter will still use the same host. The examples below illustrate the resulting URLs when this second contructor argument is used.

Examples:

   base                         relative               result

   smb://host/share/a/b      +  c/d               -->  smb://host/share/a/b/c/d
   smb://host/share/foo/bar  +  /share2/zig/zag   -->  smb://host/share2/zig/zag
   smb://host/share/foo/bar  +  ../zip            -->  smb://host/share/foo/zip
   smb://host/share/foo      +  ../../othershare  -->  smb://host/othershare
   smb://host/share/zig/zag  +  /othershare       -->  smb://host/othershare
   smb://host/share/zig/zag  +  smb://foo/bar     -->  smb://foo/bar
   smb://host/share/zig/zag  +  null              -->  smb://host/share/zig/zag
   smb://host/share/zig/zag  +  /                 -->  <exception: at least share must be specified>
  
Instances of the SmbFile class are immutable; that is, once created, the abstract pathname represented by an SmbFile object will never change.


Constructor Summary
SmbFile(SmbFile file, String name)
          Constructs an SmbFile representing a file or directory on an SMB server specified by the SmbFile augmented with the named path.
SmbFile(String url)
          Constructs and SmbFile representing a file or directory on an SMB server specified by the URL argument.
SmbFile(String url, String name)
          Constructs an SmbFile representing a file or directory on an SMB server specified by the URL argument and the possibly null relative path.
 
Method Summary
 boolean canRead()
          Tests to see if the file this SmbFile represents is marked read-only.
 boolean canWrite()
          Tests to see if the file this SmbFile represents is not marked read-only.
 boolean delete()
          Deletes the file on the SMB server that this SmbFile represents.
 boolean equals(Object obj)
          Tests to see if two SmbFile objects are equal by comparing hashCodes.
 boolean exists()
          Tests to see if the file this SmbFile represents exists on the server.
 String getCanonicalPath()
          Returns the full URL with '..' and '.' components factored out.
 String getName()
          Returns the last component of the path.
 String getParent()
          Returns everything but the last component of the path.
 String getPath()
          Returns the full URL.
 int hashCode()
          Computes a hashCode for this file based on the URL string.
 boolean isDirectory()
          Tests to see if the file this SmbFile represents is a directory.
 boolean isFile()
          Tests to see if the file this SmbFile represents is not a directory.
 boolean isHidden()
          Tests to see if the file this SmbFile represents is marked as being hidden.
 long lastModified()
          Returns the time the file this SmbFile represents was lastModified.
 long length()
          Returns the length of the file this SmbFile represents.
 String[] list()
          Returns the names of files and directorys listed under the directory this SmbFile represents.
 boolean mkdir()
          Creates a directory with the path specified by this SmbFile.
 boolean renameTo(SmbFile dest)
          Changes the name of the file this SmbFile represents to the name designated by the SmbFile argument(Remember SmbFiles are immutible and therefore the path associated with this SmbFile object will not change).
 String toString()
          Returns the string representation of this SmbFile object.
 URL toURL()
          Returns the URL representation of the file this SmbFile represents.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SmbFile

public SmbFile(String url)
        throws MalformedURLException,
               UnknownHostException
Constructs and SmbFile representing a file or directory on an SMB server specified by the URL argument. See the description and examples of smb URLs above.

SmbFile

public SmbFile(String url,
               String name)
        throws MalformedURLException,
               UnknownHostException
Constructs an SmbFile representing a file or directory on an SMB server specified by the URL argument and the possibly null relative path. See the description and examples of using the second parameter above.

SmbFile

public SmbFile(SmbFile file,
               String name)
        throws MalformedURLException,
               UnknownHostException
Constructs an SmbFile representing a file or directory on an SMB server specified by the SmbFile augmented with the named path. See the description and examples of using the second parameter above.
Method Detail

getName

public String getName()
Returns the last component of the path.

getParent

public String getParent()
Returns everything but the last component of the path.

getPath

public String getPath()
Returns the full URL.

getCanonicalPath

public String getCanonicalPath()
Returns the full URL with '..' and '.' components factored out.

exists

public boolean exists()
Tests to see if the file this SmbFile represents exists on the server.

canRead

public boolean canRead()
Tests to see if the file this SmbFile represents is marked read-only.

canWrite

public boolean canWrite()
Tests to see if the file this SmbFile represents is not marked read-only.

isDirectory

public boolean isDirectory()
Tests to see if the file this SmbFile represents is a directory.

isFile

public boolean isFile()
Tests to see if the file this SmbFile represents is not a directory.

isHidden

public boolean isHidden()
Tests to see if the file this SmbFile represents is marked as being hidden.

lastModified

public long lastModified()
Returns the time the file this SmbFile represents was lastModified.

list

public String[] list()
Returns the names of files and directorys listed under the directory this SmbFile represents.

renameTo

public boolean renameTo(SmbFile dest)
Changes the name of the file this SmbFile represents to the name designated by the SmbFile argument(Remember SmbFiles are immutible and therefore the path associated with this SmbFile object will not change).

delete

public boolean delete()
Deletes the file on the SMB server that this SmbFile represents.

length

public long length()
Returns the length of the file this SmbFile represents.

mkdir

public boolean mkdir()
Creates a directory with the path specified by this SmbFile.

toURL

public URL toURL()
          throws MalformedURLException
Returns the URL representation of the file this SmbFile represents.

hashCode

public int hashCode()
Computes a hashCode for this file based on the URL string.
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Tests to see if two SmbFile objects are equal by comparing hashCodes.
Overrides:
equals in class Object

toString

public String toString()
Returns the string representation of this SmbFile object.
Overrides:
toString in class Object