Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6128797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:40:03+00:00 2026-05-23T16:40:03+00:00

just 3 days ago I am getting the following error message when I am

  • 0

just 3 days ago I am getting the following error message when I am trying to upload a PDF file… not sure why it is not working now…. I haven´t changed anything, could it be the server?

This is the error I am getting :

java.lang.IndexOutOfBoundsException
java.io.FileOutputStream.writeBytes(Native Method)
java.io.FileOutputStream.write(FileOutputStream.java:260)

exception

org.apache.jasper.JasperException: Exception in JSP: /drawingUp.jsp:48

45:         File savedFile = new File(folder +"/IngDemo/drawings/"+saveFile) ;
46:         FileOutputStream fileOut = new FileOutputStream(savedFile); 
47:         //FileOutputStream fileOut = new FileOutputStream(savedFile);
48:         fileOut.write(dataBytes, startPos, (endPos - startPos));
49:         fileOut.flush();
50:         fileOut.close();

Any clues of what it could be would be appreciated…..
Thanks

This is more of the code:

String contentType = request.getContentType();
//here we are checking the content type is not equal to Null and
 //as well as the passed data from multipart/form-data is greater than or
 //equal to 0
if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0))
 {
    DataInputStream in = new DataInputStream(request.getInputStream());
    //we are taking the length of Content type data
    int formDataLength = request.getContentLength();
    byte dataBytes[] = new byte[formDataLength];
    int byteRead = 0;
    int totalBytesRead = 0;
    //this loop converting the uploaded file into byte code
    while (totalBytesRead < formDataLength) {
        byteRead = in.read(dataBytes, totalBytesRead,formDataLength);
        totalBytesRead += byteRead;
        }
    String file = new String(dataBytes);
    //for saving the file name
    String saveFile = file.substring(file.indexOf("filename=\"") + 10);
    saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
    saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1,saveFile.indexOf("\""));
    int lastIndex = contentType.lastIndexOf("=");
    String boundary = contentType.substring(lastIndex + 1,contentType.length());
    int pos;
    //extracting the index of file 
    pos = file.indexOf("filename=\"");
    pos = file.indexOf("\n", pos) + 1;
    pos = file.indexOf("\n", pos) + 1;
    pos = file.indexOf("\n", pos) + 1;
    int boundaryLocation = file.indexOf(boundary, pos) - 4;
    int startPos = ((file.substring(0, pos)).getBytes()).length;
    int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;
    // creating a new file with the same name and writing the 
//content in new file
    String folder = (String) new File(config.getServletContext().getRealPath("/")).getParent();
    folder= (String)folder.replace(File.separatorChar, '/');
    File savedFile = new File(folder +"/IngDemo/drawings/"+saveFile) ;
    FileOutputStream fileOut = new FileOutputStream(savedFile); 
    //FileOutputStream fileOut = new FileOutputStream(savedFile);
    fileOut.write(dataBytes, startPos, (endPos - startPos));
    fileOut.flush();
    fileOut.close();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:40:04+00:00Added an answer on May 23, 2026 at 4:40 pm

    How are endPos and startPos being calculated? Your problem is almost certainly that one or both of these values is incorrect.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just started working with Mercurial a few days ago and there's something I don't
I just started learning Common Lisp a few days ago, and I'm trying to
I've been trying to solve this for ages (3 days) now and I just
I just started with Java servlets few days ago. I am trying to develop
I just started learning SQL a couple of days ago, and I'm trying to
I just updated my website like 2 days ago and now it has new
Just some days ago I started looking into a unit test framework called check,
I've spent the past two days just trying to enable the sending of email
I just wrote a stored function to calculate the working days between two dates.
I asked this a couple of days ago on Server Fault but am getting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.