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 t开发者_运维知识库he 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
Okay, I wasn't doing this quite right. What I really needed was:
for(File file : rtfTemplateList){
try {
fileInputStream = new FileInputStream(file);
byte[] byteArray = new byte[(int) file.length()];
fileInputStream.read(byteArray);
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArray);
etc...
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.
精彩评论