• Post Reply Bookmark Topic Watch Topic
  • New Topic

Write image to specific image directory?  RSS feed

 
Daan Heuvelbeuk
Ranch Hand
Posts: 85
MySQL Database Netscape Windows XP
  • Mark post as helpful
  • send pies
  • 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.
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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: 85
MySQL Database Netscape Windows XP
  • Mark post as helpful
  • send pies
  • 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: 85
MySQL Database Netscape Windows XP
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!