java - Apache Commons VFS - 如何设置文件的大小......?

标签 java apache-commons-vfs

我似乎无法在 FileObject 或 FileContent 上找到任何允许我在现有文件上设置新大小的方法。

FileContent.getSize() 没有对应的 setSize()RandomAccessContent 确实有一些关于查找的评论,但它似乎没有说明如果在结尾之前查找某处然后简单地关闭文件,文件将会缩小。

/**
 * Sets the file-pointer offset, measured from the beginning of this
 * file, at which the next read or write occurs.  The offset may be
 * set beyond the end of the file. Setting the offset beyond the end
 * of the file does not change the file length.  The file length will
 * change only by writing after the offset has been set beyond the end
 * of the file.
 * <br/>
 * <b>Notice: If you use {@link #getInputStream()} you have to reget the InputStream after calling {@link #seek(long)}</b>
 *
 * @param pos the offset position, measured in bytes from the
 *            beginning of the file, at which to set the file
 *            pointer.
 * @throws IOException if <code>pos</code> is less than
 *                     <code>0</code> or if an I/O error occurs.
 */
public void seek(long pos) throws IOException;

最佳答案

使用公共(public) API,您无法设置大小或截断任何文件。然而,一些专门的类型确实提供了一种可以使用的方法。也就是说,该方法也可能不是公开的,需要进行讨厌的反射。

关于java - Apache Commons VFS - 如何设置文件的大小......?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6731392/

相关文章:

java - Junit错误:java. lang.IllegalStateException:无法加载ApplicationContext

java - 无法从 Android 中的 Firebase 存储获取下载网址

java - 如何将 JCIFS 与 apache VFS 结合使用来访问 SMB URL?

java - 如何使用apache common vfs上传字节数组

java - 如何修复使用 Apache Commons VFS 将文件上传到 SFTP 服务器时发生的错误

java - Jackson 的只写属性

java - 纵向模式下带有图标和文本的 ActionBar

java - 从jspinner中删除逗号

java - Commons VFS - 无法列出目录的内容

java - Apache commons VFS 未知方案文件