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 6619543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:58:58+00:00 2026-05-25T20:58:58+00:00

Problem Context: I am trying to persist a file, uploaded by the user, to

  • 0

Problem Context:

I am trying to persist a file, uploaded by the user, to file system.

Description:

Actually, I am using Spring MVC (3.0) and this is how I am trying to persist the file,

String orgName = file.getOriginalFilename();
String filePath = "/Uploads/MyUploads/"+ new Date().getTime()+orgName;// Unique Image Name
File dest = new File(filePath);
file.transferTo(dest);

I have a folder Uploads\MarketplaceUploads, at the root of my application. But still I am getting FileNotFoundException "\Uploads\MyUploads\loading.gif (The system cannot find the path specified)”.

Below is the directory structure:

enter image description here

  • 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-25T20:58:58+00:00Added an answer on May 25, 2026 at 8:58 pm

    Ensure you add the web-app context path before using the file

    String orgName = file.getOriginalFilename();
    String filePath = getServletContext().getRealPath("/") + "/Uploads/MyUploads/"+ new Date().getTime()+orgName;// Unique Image Name
    File dest = new File(filePath);
    file.transferTo(dest);
    

    From the javadoc of getRealPath()

    Gets the real path corresponding to the given virtual path.
    For example, if path is equal to /index.html, this method will return the absolute file path on the server’s filesystem to which a request of the form http://://index.html would be mapped, where corresponds to the context path of this ServletContext.
    The real path returned will be in a form appropriate to the computer and operating system on which the servlet container is running, including the proper path separators.
    Resources inside the /META-INF/resources directories of JAR files bundled in the application’s /WEB-INF/lib directory must be considered only if the container has unpacked them from their containing JAR file, in which case the path to the unpacked location must be returned.
    This method returns null if the servlet container is unable to translate the given virtual path to a real path.

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

Sidebar

Related Questions

I'm having the following problem. I created a application context file for spring.net. The
I am trying to complete the Spring MVC tutorial at: http://static.springsource.org/docs/Spring-MVC-step-by-step/part1.html My problem is
For a little context, i'm trying to solve Project Euler problem 31 using excellent
Context I'm learning C, and I'm trying to reverse a string in place using
I'm trying to make a project using Spring MVC and JPA but I have
For context - read this . Problem: class Program { static void Main() {
Context: I'm trying to improve the values returned by the iPhone CLLocationManager, although this
I'm having a problem trying to add an object to an object context in
I'm trying to make a database in android but I have this problem,erase the
I'm trying to load a collection of entities using Linq2SQL. The problem is, I

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.