• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

upload

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I use this code for upload:

public void doPost ...
{

.....
FileOutputStream fout = new FileOutputStream(cale+"/" + "file.txt");
final int BUFFER_SIZE = 8192;
....
ServletInputStream in = request.getInputStream();
....
}
try
{
int contentLength = request.getContentLength();
String contentType = request.getContentType();

ServletInputStream in = request.getInputStream();

byte[] buffer = new byte[BUFFER_SIZE];

int i=0;
int result1=0;
int result=1;
while (true)
{
i++;
if (i<=4)
result1 = in.readLine(buffer, 0, BUFFER_SIZE);
else
result = in.readLine(buffer, 0, BUFFER_SIZE);
if (result <= 0)
{
break;
}
if (i>4)
fout.write(buffer, 0, result);
}
}
catch (IOException e)
{
}
finally
{
fout.close();
}
The original txt file looks like this:
1
2
3

But the uploaded file looks like this:
-----------------------------7d41ae27e2c
Content-Disposition: form-data; name="fupload"; filename="C:\My Documents\test.txt"
Content-Type: text/plain

1
2
3
-----------------------------7d41ae27e2c--

I manage to skip the first 4 lines( with the i variable and the tests) but i can skip the last line (-----------------------------7d41ae27e2c)

Now, the uploaded file looks loke this:
1
2
3
-----------------------------7d41ae27e2c--

HOW CAN I UPLOAD THE FILE WITHOUT THE LAST LINE? DO YOU SEE OTHER SOLUTION OF UPLOADING?

THNX!
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Theres a lot more going on then you see right there. The easiest is to use Jakarta Commons FileUpload
 
eat bricks! HA! And here's another one! And a tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic