Hi, I am use the File Upload. I need to read the whole file contents in a
String buffer. If the file is text, it works. But if the file is in other
format, such as MS Doc, I can load the file, and the file size is the same
comparing the original file, but the format is changed, and I cannot open
it. The related code in a servlet is as following:
.....
int nSize=0;
// now !item.isFormField()
java.io.InputStream fstrm = item.getInputStream();
int rnum=0;
buf = new byte[262144]; // the doc file size I am testing is
13XXXX buyes.
while (rnum>=0){ // I have to read all the contents
rnum = fstrm.read(buf, (int)nSize, 100);
if (rnum> 0) nSize += rnum;
}
fstrm.close();
if ( nSize>0) {
pBuffer = new String(buf, 0, (int)nSize);
// I like to test if it read correctly:
FileWriter fileOut = new
FileWriter("C:/DocAttachment/strFileName.doc");
fileOut.write(pBuffer);
fileOut.flush();
fileOut.close();
......
}
I use Apache2 and Tomcat5.
Please forward instruction.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]