I need to send files from Java Client application to servlet.
The code work fine but when the length of file is too big I get
OutOfMemoryError.

How can I to solve this problem.

Thanks in advance,
Torondel

-----------------
My sample code:

        File target = new File("MyFile");
        try {
            HttpURLConnection connection = (HttpURLConnection)
url.openConnection();
          connection.setDoOutput(true);
          connection.setDoInput(true);
          connection.setUseCaches(false);
          connection.setRequestMethod("POST");
          connection.setRequestProperty("Content-Type", "
application/octet-stream");
          connection.setRequestProperty("Content-Length", " " +
target.length());
        }
        catch (Exception e) {}

      try {
          destination = new
BufferedOutputStream(connection.getOutputStream(),8*1024);
          source = new BufferedInputStream(new FileInputStream( target ));

            buffer = new byte[100 * 1024];
          while(true) {
                  bytes_read = source.read(buffer,0, buffer.length);
              if (bytes_read == -1) break;
                destination.write(buffer, 0, bytes_read);
          }
          destination.flush();
        }
      finally {
          if (source != null)
              try { source.close(); } catch (IOException e) { ; }
          if (destination != null)
              try { destination.close(); } catch (IOException e) { ; }
      }

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to