如何从rtf文档文件的文件列表中获取InputStream?
我有一个 richTextFormat 文档列表,我需要循环遍历并从每个文件中获取 InputStream 以与另一个文档合并。我使用此代码来获取文件:
List<File> rtfFilesList = new ArrayList<File>();
File[] files = new File(<path to files>).listFiles();
for (File file : files) {
if (file.isFile() && file.getName().endsWith(".rtf")) {
FilenameUtils.removeExtension(".rtf");
rtfFilesList.add(file);
}
}
这让我可以很好地获取文件,但现在我想循环遍历列表,如下所示:
for(File file : rtfFilesList){
//Get the document stream from each file here.
...
我不知道如何将文件转换为特定类型的文件。 API 似乎并不真正支持这一点。
对这个有什么想法吗?
谢谢, 詹姆斯
I have a list of richTextFormat documents that I need to loop through and get the InputStream from each file to merge with another document. I used this code to get the files:
List<File> rtfFilesList = new ArrayList<File>();
File[] files = new File(<path to files>).listFiles();
for (File file : files) {
if (file.isFile() && file.getName().endsWith(".rtf")) {
FilenameUtils.removeExtension(".rtf");
rtfFilesList.add(file);
}
}
That gets me the files fine, but now I want to loop through the list, as in:
for(File file : rtfFilesList){
//Get the document stream from each file here.
...
I don't know how to get the File cast to a specific type of file. API didn't seem to really support that.
Any ideas on this one?
Thanks,
James
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我做得不太对。我真正需要的是:
在写下我想做的事情后,我发现真正获得一个 byteArrayInputStream 传递给第三方软件生成器以创建合并的 rtf 文件。因此,在 for 循环中使用该文件是正确的,但之后我只需要获取流即可。
我希望这对某人有帮助。
Okay, I wasn't doing this quite right. What I really needed was:
What I found after writing down what I wanted to do was really get a byteArrayInputStream to pass to a third party software generator to create a merged rtf file. So using the file in a for loop was correct, but then I just needed to get the stream after that.
I hope this helps someone.