Thanks. It works.
-----Original Message-----
From: Steffen Heil [mailto:[EMAIL PROTECTED]
Sent: Thursday, October 28, 2004 10:49 AM
To: 'Tomcat Users List'
Subject: AW: Upload MS DOC or Image file errors.
Hi
> Hi, I am use the File Upload. I need to read the whole file contents in a
String buffer.
Why into a String buffer?
This is propably a charset encoding problem.
Do NOT read it into a stringbuffer.
See FileWriter documentation:
> FileWriter is meant for writing streams of characters. For writing streams
of raw bytes, consider using a FileOutputStream.
So change your method:
.....
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) {
// I like to test if it read correctly:
FileOutputStream fileOut = new
FileOutputStream("C:/DocAttachment/strFileName.doc");
fileOut.write(buf, 0, nSize);
fileOut.flush();
fileOut.close();
......
}
Beside that:
You know that you could simply do:
item.write( new File( "C:/DocAttachment/strFileName.doc" ) );
Regards,
Steffen
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]