• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Unable to create a file using java.io.File

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have attached my code


The problem is, no exception is thrown in
'

but, a FileNotFoundException is thrown in


Also, it specifies the Absolute Path, but when I check there, there is no file created.


Any help is appreciated.
TIA
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't mention which implementation of MultipartFile you are using, but if it exists on disk, it probably doesn't have the original file name (hence the method getOriginalFilename). What you probably want to do is move the file from its temporary storage location to a known location and manipulate the file there.
 
vinitha simon
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm uploading the zip file as an instance of multipartfile in my Spring's Controller, the controller passes on the file to the workflow, where I'm trying to validate the contents of the zip file. In order to validate the contents, I'm first creating an instance of the file,

File tempFile = new File("C:/workspace/tempData/" + fileName);

this creates a file with the originalFileName, which maybe 'sample.zip'. When I debug, the 'fileName' exists,

also, it says the file is created, it provides me with the absolutepath as well.....,

but, to validate the contents of a Zip from a multipartfile, do you have any other suggestions...


TIA
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I haven't used Spring, but a quick look at the documentation validates what I said above:

The file contents are either stored in memory or temporarily on disk. In either case, the user is responsible for copying file contents to a session-level or persistent store as and if desired. The temporary storages will be cleared at the end of request processing.



There are methods in MultipartFile to facilitate moving the data, namely getInputStream and transferTo. Once you've copied the file, you are free to do your validation.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic