當前位置: 首頁>>代碼示例>>Java>>正文


Java SmbFile.exists方法代碼示例

本文整理匯總了Java中jcifs.smb.SmbFile.exists方法的典型用法代碼示例。如果您正苦於以下問題:Java SmbFile.exists方法的具體用法?Java SmbFile.exists怎麽用?Java SmbFile.exists使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在jcifs.smb.SmbFile的用法示例。


在下文中一共展示了SmbFile.exists方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: performListing

import jcifs.smb.SmbFile; //導入方法依賴的package包/類
private Set<SmbFile> performListing(final SmbFile directory2, final boolean recurseSubdirectories) throws SmbException {
    if (!directory2.canRead() || !directory2.canWrite()) {
        throw new IllegalStateException("Directory '" + directory2 + "' does not have sufficient permissions (i.e., not writable and readable)");
    }
    final Set<SmbFile> queue = new HashSet<SmbFile>();
    if (!directory2.exists()) {
        return queue;
    }

    final SmbFile[] children = directory2.listFiles();
    if (children == null) {
        return queue;
    }

    for (final SmbFile child : children) {
        if (child.isDirectory()) {
            if (recurseSubdirectories) {
                queue.addAll(performListing(child,  recurseSubdirectories));
            }
        } else  {
            queue.add(child);
        }
    }

    return queue;
}
 
開發者ID:dream-lab,項目名稱:echo,代碼行數:27,代碼來源:GetSmbFiles.java

示例2: checkAccess

import jcifs.smb.SmbFile; //導入方法依賴的package包/類
/**
 * Checks access to file under the provided {@link SMBPath}.
 *
 * @param path {@link SMBPath} for which access should be checked.
 * @param modes AccessModes that should be checked. Onl yREAD and WRITE are supported.
 *
 * @throws NoSuchFileException If file or folder specified by {@link SMBPath} does not exist.
 * @throws AccessDeniedException If requested access cannot be provided for file or folder under {@link SMBPath}.
 * @throws IllegalArgumentException If provided path is not a {@link SMBPath} instance.
 * @throws IOException If checking accessfails for some reason.
 */
@Override
public void checkAccess(Path path, AccessMode... modes) throws IOException {
    SmbFile smbFile = SMBPath.fromPath(path).getSmbFile();

    /* First check if file exists. */
    if (!smbFile.exists()) throw new NoSuchFileException("The specified SMB resource does not exist.");

    /* Determin which attributes to check. */
    boolean checkRead = false;
    boolean checkWrite = false;
    for (AccessMode mode : modes) {
        if (mode.equals(AccessMode.READ)) checkRead = true;
        if (mode.equals(AccessMode.WRITE)) checkWrite = true;
    }

    /* Perform necessary checks. */
    if (checkRead && !smbFile.canRead())  throw new AccessDeniedException("The specified SMB resource is not readable.");
    if (checkWrite && !smbFile.canWrite())  throw new AccessDeniedException("The specified SMB resource is not writable.");
}
 
開發者ID:pontiussoftware,項目名稱:smb-nio,代碼行數:31,代碼來源:SMBFileSystemProvider.java

示例3: SeekableSMBByteChannel

import jcifs.smb.SmbFile; //導入方法依賴的package包/類
/**
 * Constructor for {@link SeekableSMBByteChannel}
 *
 * @param file The {@link SmbFile} instance that should be opened.
 * @param write Flag that indicates, whether write access is requested.
 * @param create Flag that indicates, whether file should be created.
 * @param create_new Flag that indicates, whether file should be created. If it is set to true, operation will fail if file exists!
 * @param truncate Flag that indicates, whether file should be truncated to length 0 when being opened.
 * @param append Flag that indicates, whether data should be appended.
 * @throws IOException If something goes wrong when accessing the file.
 */
SeekableSMBByteChannel(SmbFile file, boolean write, boolean create, boolean create_new, boolean truncate, boolean append) throws IOException {

    /*  Tries to create a new file, if so specified. */
    if (create || create_new) {
        if (file.exists()) {
            if (create_new) throw new FileAlreadyExistsException("The specified file '" + file.getPath() + "' does already exist!");
        } else {
            file.createNewFile();
        }
    }

    /* Opens the file with either read only or write access. */
    if (write) {
        file.setReadWrite();
        this.random = new SmbRandomAccessFile(file, "rw");
        if (truncate) this.random.setLength(0);
        if (append) this.random.seek(this.random.length());
    } else {
        file.setReadOnly();
        this.random = new SmbRandomAccessFile(file, "r");
    }
}
 
開發者ID:pontiussoftware,項目名稱:smb-nio,代碼行數:34,代碼來源:SeekableSMBByteChannel.java

示例4: smbDel

import jcifs.smb.SmbFile; //導入方法依賴的package包/類
/**
 * 把本地磁盤中的文件從局域網共享文件中刪除
 * 
 * @param remoteUrl
 *            共享電腦路徑 如:smb//administrator:[email protected]/smb
 */
public static void smbDel(String remoteUrl) {
	try {
		SmbFile remoteFile = new SmbFile(SMBPATH + remoteUrl);
		if (remoteFile.isFile() && remoteFile.exists()) {
			remoteFile.delete();
			logger.info("刪除遠程文件 :" + remoteUrl);
		}
	} catch (Exception e) {
		logger.error(e);
	} 
}
 
開發者ID:ZiryLee,項目名稱:FileUpload2Spring,代碼行數:18,代碼來源:SmbUtil.java

示例5: exists

import jcifs.smb.SmbFile; //導入方法依賴的package包/類
@Override
public boolean exists(String srcPath) throws IOException {
	try {
		System.out.println("*** exists "+srcPath+" => "+getAbsolutePath(srcPath));
		SmbFile currentFolder = new SmbFile(getAbsolutePath(srcPath), authentication);
		return currentFolder.exists();
	} catch (Throwable t){
		t.printStackTrace();
		throw new IOException(t.getMessage());
	}
}
 
開發者ID:starn,項目名稱:encdroidMC,代碼行數:12,代碼來源:FileProvider3.java

示例6: main

import jcifs.smb.SmbFile; //導入方法依賴的package包/類
public static void main( String argv[] ) throws Exception {

        SmbFile f = new SmbFile( argv[0] );
        if( f.exists() ) {
            System.out.println( argv[0] + " exists" );
        } else {
            System.out.println( argv[0] + " does not exist" );
        }
    }
 
開發者ID:codelibs,項目名稱:jcifs,代碼行數:10,代碼來源:Exists.java

示例7: beforeClass

import jcifs.smb.SmbFile; //導入方法依賴的package包/類
@BeforeClass
void beforeClass() throws IOException {
    Properties properties = new Properties();
    InputStream propertiesInput = new FileInputStream(PROPERTIES);
    try {
        properties.load(propertiesInput);

        for (String prop : requiredProperties) {
            if (properties.getProperty(prop, "").isEmpty()) {
                throw new IllegalStateException("Missing required property " + prop + " in " + PROPERTIES);
            }
        }
        SERVER = properties.getProperty("SERVER");
        SERVER_IP = properties.getProperty("SERVER_IP");
        SHARE = properties.getProperty("SHARE");
        DIR = properties.getProperty("DIR");

        WRITE_DIR = DIR + "/";
        SRC_DIR = DIR + "/Junk/";
        FILE1 = SRC_DIR + "10883563.doc";
        URL_SERVER = "smb://" + SERVER + "/";
        URL_SHARE = URL_SERVER + SHARE + "/";
        URL_WRITE_DIR = URL_SHARE + WRITE_DIR;

        for (Map.Entry<Object,Object> propEntry : properties.entrySet()) {
            System.setProperty((String)propEntry.getKey(), (String)propEntry.getValue());
        }

        SmbFile dir = new SmbFile(URL_WRITE_DIR);
        if (dir.exists()) {
            dir.delete();
        }
        SmbFile srcDir = new SmbFile(URL_SHARE + SRC_DIR);
        if (!srcDir.exists()) {
            srcDir.mkdirs();
        }
        SmbFile file1 = new SmbFile(URL_SHARE + FILE1);
        if (!file1.exists()) {
            file1.createNewFile();
            OutputStream os = file1.getOutputStream();
            try {
                IOUtils.copy(getClass().getResourceAsStream("10883563.doc"), os);
            } finally {
                IOUtils.closeQuietly(os);
            }
        }

    } finally {
        IOUtils.closeQuietly(propertiesInput);
    }
}
 
開發者ID:IdentityAutomation,項目名稱:jcifs-idautopatch,代碼行數:52,代碼來源:JCIFSTest.java


注:本文中的jcifs.smb.SmbFile.exists方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。