- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个名为 data.dat
的文件,我想将其加载到 Vaadin 中的 byte[]
中。这是一个数据文件,我需要加载然后根据用户的输入进行操作。
我尝试过:
String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath();
FileResource resource = new FileResource(new File(basepath + MY_DATA_FILE));
问题是我不知道如何操作资源
来提取byte[]
。我明白了lots of information for how to put images and so on to the UI components , how to stream a user generated PDF等等,但我似乎找不到任何有关如何加载自己的数据文件然后在代码中进行操作的示例...
最佳答案
从 vaadin 的文档中你可以得到:
java.io.File getSourceFile()
Gets the source file.
或
DownloadStream getStream()
Gets resource as stream.
在DownloadStream
中:
java.io.InputStream getStream()
Gets downloadable stream.
这样你就可以轻松地操作File
或InputStream
来读取FileResource
的内容
例如在 Java 8 中:
byte[] bytes = Files.readAllBytes(Paths.get(resource.getSourceFile().getAbsolutePath()));
关于java - 如何将 FileResource 加载到字节数组中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31465974/
使用FileResource来自edu.duke,如何在像这样打开文件之前检查文件是否存在? FileResource auxFr = new FileResource("/testing/yob"
我有一个名为 data.dat 的文件,我想将其加载到 Vaadin 中的 byte[] 中。这是一个数据文件,我需要加载然后根据用户的输入进行操作。 我尝试过: String basepath =
如何将 FileResource 转换为 String? 现在我有这个: FileResource resource = new FileResource("data/someText.txt");
我正在使用Icefaces 。我为用户生成报告并使用 FileResource 类提供它。我对该文件不执行任何操作,因为只要用户单击资源链接,就应该可以下载该文件。 但是,用户注销后,不再需要该报告,
我是一名优秀的程序员,十分优秀!