• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Write image to specific image directory?

 
Ranch Hand
Posts: 89
Netscape MySQL Database Windows XP
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my application the users must be able to load their own logo and display it in, for instance, their invoices. To find the image (the user logo) they want to use I use the JFileChooser. I succeed in writing the image, but the image comes in the image directory of my (Eclipse) workspace, not in the directory in my package structure, where the other image files reside. What can I do?

My directory structure under Windows XP (I know, ):


The image comes in my images directory. I want to get it in the foo/bar/images directory.

To get the images I use

I tried it with
which resulted in a FileNotFoundException

And I thought the location I wanted to save the image to (almost) correct (I doubt the 'file:\' part) in the Stack Trace.
 
Sheriff
Posts: 7113
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The "file:" part is coming from the URL class. I believe you can do something like imgURL.toString() to get rid of it.
 
Saloon Keeper
Posts: 9562
79
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why open up the image and then save it? You could just copy the bytes from one file to another ignoring the fact that they just happen to represent an image.
 
Daan Heuvelbeuk
Ranch Hand
Posts: 89
Netscape MySQL Database Windows XP
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:Why open up the image and then save it? You could just copy the bytes from one file to another ignoring the fact that they just happen to represent an image.



Yes, you are right. But I was thinking to first show the image in the application, then to save it to the prescribed location, and lastly save the location to the database. However, copying the image first, and then opening is not something I thought about. But would I not have the same problem finding the location it has to be copied to?

Knute Snortum wrote:The "file:" part is coming from the URL class. I believe you can do something like imgURL.toString() to get rid of it.



I tried it by changing line 5 in the one for last piece of code to

The result is however the same
 
Daan Heuvelbeuk
Ranch Hand
Posts: 89
Netscape MySQL Database Windows XP
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found the answer.



With the saveImage method as follows (with the catch inside the try clause):

I think I found an operating system independent solution.
 
"How many licks ..." - I think all of this dog's research starts with these words. Tasty tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic