本文整理汇总了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();
}
**/
}