Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > FileWriting Problem using Servlet

Thread Tools

FileWriting Problem using Servlet

Emery Z. Balint Jr.
Posts: n/a
My objective here is to have a place where users could upload an image file
to the server. I'm using a form with encType set to multipart/form-data and
I've read up on how to extract the data that comes through. Easy enough,
except that for some reason when I get to the part of extracting the files,
I get corrupt data.

Below I've tried using PrintWriter (which works the best so far)
FileOutputStreams and even nio with a ByteBuffer. Anything that writes
binary stream hasn't worked at all, the file sizes that occur are several
times larger than the original, hence why I stuck with PrintWriter. The test
file written with this code below ends up having exactly the same file size
as the original, but again with corrupt data. I'm a little lost at this
point, as according to most documents I found on the subject I should be
doing this correctly. Many thanks in advance for any assistance!

Sun Certified Java Programmer
E-stronomy - Astronomical Resources
Talking with Tonz - Dance/Alternative Music

File file1 = new File("tester.png");
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file1)));

while (lineSize!=-1 && !nextLine.startsWith(delimiter)) {
lineSize = in.readLine(inLine, 0, 1024);
if ((lineSize==delimiter.length()+4)
&& (new String(inLine, 0, lineSize).startsWith(delimiter))) {

nextLine = nextLine.substring(0, nextLine.length()-2);

} else {

nextLine = new String(inLine, 0, lineSize);


Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Keeping session with Servlet to Servlet communications DiscoStu Java 0 07-08-2004 06:50 PM
Offending class: javax/servlet/Servlet.class chamikara Java 1 06-19-2004 05:42 AM
Servlet question(Tomcat, web.xml, servlet-class, servlet-name) circuit_breaker Java 2 04-04-2004 03:26 AM
Tomcat: POST from one servlet or internal class to another servlet Sean Clarke Java 1 01-07-2004 02:22 PM
how to get my servlet configuration before the servlet is initialised Andy Fish Java 4 12-17-2003 09:47 PM