本文整理匯總了Java中org.apache.commons.vfs2.FileObject.close方法的典型用法代碼示例。如果您正苦於以下問題:Java FileObject.close方法的具體用法?Java FileObject.close怎麽用?Java FileObject.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.vfs2.FileObject
的用法示例。
在下文中一共展示了FileObject.close方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: close
import org.apache.commons.vfs2.FileObject; //導入方法依賴的package包/類
@Override
public void close(FileObject fileObject) {
try {
fileObject.close();
} catch (FileSystemException e) {
e.printStackTrace();
}
}
示例2: writeToSFTP
import org.apache.commons.vfs2.FileObject; //導入方法依賴的package包/類
protected void writeToSFTP(String filename, int random_num) {
String connectionStr = baseConnectionStr + "/" + filename;
if(debug) System.err.println(connectionStr);
try {
// Create remote file object
FileObject remoteFile = manager.resolveFile(connectionStr, fileSystemOptions);
FileContent fc = remoteFile.getContent();
OutputStream ostream = fc.getOutputStream();
if(ostream==null) {
throw new IOException("Error opening output stream to SFTP");
}
// Write content to file
PrintWriter pw = new PrintWriter(ostream);
pw.format("%06d\n",random_num);
pw.close();
// Cleanup
if (remoteFile != null) remoteFile.close();
} catch (Exception e) {
e.printStackTrace();
}
/**
// Here's an alternate approach that creates a local file and then copies the
// local file to remote directory
// Create the local file
File local_file = new File("C:\\TEMP\\TEST",filename);
try {
FileWriter fw = new FileWriter(local_file,false);
PrintWriter pw = new PrintWriter(fw);
// Write out the index and a random number to the file
pw.format("%06d\n",random_num);
pw.close();
} catch (Exception e) {
e.printStackTrace();
}
// Copy the local file to remote SFTP server
try {
// Create local file object
FileObject localFile = manager.resolveFile(local_file.getAbsolutePath());
// Create remote file object
FileObject remoteFile = manager.resolveFile(connectionStr, fileSystemOptions);
// Copy local file to SFTP server
remoteFile.copyFrom(localFile, Selectors.SELECT_SELF);
} catch (Exception e) {
e.printStackTrace();
}
**/
}