本文整理匯總了Java中org.apache.commons.vfs2.FileObject.getURL方法的典型用法代碼示例。如果您正苦於以下問題:Java FileObject.getURL方法的具體用法?Java FileObject.getURL怎麽用?Java FileObject.getURL使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.vfs2.FileObject
的用法示例。
在下文中一共展示了FileObject.getURL方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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);
}
}