本文整理汇总了Java中org.apache.commons.vfs2.FileObject.copyFrom方法的典型用法代码示例。如果您正苦于以下问题:Java FileObject.copyFrom方法的具体用法?Java FileObject.copyFrom怎么用?Java FileObject.copyFrom使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.vfs2.FileObject
的用法示例。
在下文中一共展示了FileObject.copyFrom方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: saveToTargetLocation
import org.apache.commons.vfs2.FileObject; //导入方法依赖的package包/类
@Override
public void saveToTargetLocation(File tmpFile, String targetDir) throws FileSystemException, IOException {
if (tmpFile == null)
throw new NullPointerException("tmpFile cannot be null");
if (!tmpFile.exists())
throw new FileNotFoundException(
"Unable to save file '" + tmpFile.getAbsolutePath() + "' to target location as it does not exist");
FileObject tmpFO = null;
FileObject targetDirFO = null;
FileObject targetFileFO = null;
try {
FileSystemManager fsManager = fileSystemManager();
// Tmp file.
tmpFO = fsManager.resolveFile(tmpFile.getAbsolutePath());
// Where to copy tmp file to.
targetDirFO = get(targetDir);
targetFileFO = get(new File(targetDir, tmpFile.getName()).getAbsolutePath());
// Attempt to create directories if they do not exist.
if (!targetDirFO.exists())
targetDirFO.createFolder();
if (targetDirFO.exists()) {
log.info("Saving file'" + tmpFO.getURL() + "' to '" + targetFileFO.getURL() + "'.");
targetFileFO.copyFrom(tmpFO, Selectors.SELECT_SELF);
} else {
throw new FileSystemException(
"Attempt to create target dir '" + targetDirFO.getURL().toString() + "' failed");
}
if (targetDirFO == null || !targetDirFO.exists())
throw new FileSystemException("Tmp file '" + tmpFO.getURL()
+ "' could not be copied to target locaton '" + targetFileFO.getURL() + "'");
} finally {
close(tmpFO);
close(targetDirFO);
close(targetFileFO);
}
}
示例2: copyFrom
import org.apache.commons.vfs2.FileObject; //导入方法依赖的package包/类
/**
* Copy from.
*
* @param srcFile the src file
* @param destFile the dest file
* @param selector the selector
* @throws FileSystemException the file system exception
*/
public void copyFrom(FileObject srcFile, FileObject destFile, FileSelector selector) throws FileSystemException {
// MIS-203
refreshFtpCache(srcFile);
destFile.copyFrom(srcFile, selector);
}