• Post Reply Bookmark Topic Watch Topic
  • New Topic

streaming in a microsoft word doc corrupts file  RSS feed

 
Mike Corriston
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I'm trying to stream in a doc file from a shared drive. I'm going with a fairly standard approach, I supply the path as a constructor to a file object, then chain together a fileinputstream and bufferedinputstream and write the bytes out to another file on my local drive. The stream is successful, the problem is when I open the file, winword.exe generates an error and closes. I've tried converting the file to a url, no luck. Any suggestions?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you''ll probably need to post some code here to get useful feedback on this question. How exactly do you transfer bytes from the input stream to the output stream? And do you flush() the output stream when you're done?
 
Mike Corriston
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I was actually able to figure it out, *I think*. The code I was using was as such:
try {
File pullFile = new File("E:\\TEMPLATE\\62-3011.dot");
FileReader fr = new FileReader(pullFile);
BufferedReader br = new BufferedReader(fr);
File extEDMSFile = new File("C:\\testOut.doc");
FileOutputStream fos = new FileOutputStream(extEDMSFile);
PrintStream ps = new PrintStream(fos);

while((line = br.readLine()) != null) {
ps.println(line);
}

fr.close();
br.close();
fos.close();
ps.close();
catch() {
}
when I download the file and stream it out to the testOut file, and open it in word, I get the following error, the file or path is incorrect, check the security settings, something to that effect. I used to get a winword.exe generated error but since I started downloading the file using Reader classes I don't get that anymore. The reason I think I figured it out is because of the .dot extension. I run the same code downloading a conventional .doc file and it works fine. There must be some sort of security contraint that prevent the streaming of .dot files from being successful.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think readLine doesn't give you the EOL-character, which might be suspicious, since doc-files contain binary data, which might use \n \r \n\r.
So I wouldn't recommend simply adding a newline to each printed line, but use a Stream or Reader which reads a buffer of bytes, and write bytes accordingly.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!