saving Jpeg to a specified location (linux)

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Tan T
Posts: 7
Joined: Mon Feb 09, 2004 7:09 pm
Contact:

saving Jpeg to a specified location (linux)

Post by Tan T » Tue Feb 10, 2004 8:18 pm

Hello,

I am currently trying to save the jpeg that is created using
ChartUtilities.saveChartAsJPEG into a specified location on my
harddrive. I have tried prepending the the jpg file with a path like:

ChartUtilities.saveChartAsJPEG(new File("images/" + Fname + Lname + Cycle + dateFormat + ".jpg"), chart, 650, 450); //width height

after doing this my application does not function properly and returns a null. I cant seem to save these files where I would like them to be saved. I would be very appreciative of the responses. Thanks!

r,
TT
Last edited by Tan T on Tue Feb 10, 2004 10:43 pm, edited 2 times in total.

samy2004

Post by samy2004 » Tue Feb 10, 2004 9:14 pm

I have he same issue.
while running webapps using weblogic.
help appreciated.

Thanks!

Tan T
Posts: 7
Joined: Mon Feb 09, 2004 7:09 pm
Contact:

Post by Tan T » Tue Feb 10, 2004 9:33 pm

still trying to solve! Stay in touch!

phamdinhnguyen
Posts: 22
Joined: Thu Jan 29, 2004 8:28 pm

Post by phamdinhnguyen » Tue Feb 10, 2004 10:03 pm

Did you check the directory / files access rights?
JAT

Tan T
Posts: 7
Joined: Mon Feb 09, 2004 7:09 pm
Contact:

Post by Tan T » Tue Feb 10, 2004 10:19 pm

Hello,

I am not sure what you are referring too??? I am logged on as root on my machine I have rights to all files and directories.

Currently the jpg files are being created in:

/var/tomcat4

I want the jpg files to be created in:

/var/tomcat/webapps/Assignment1/jsp/images

After saving them into the images folder, I can than use the jpg images and call them from my JSP page.

r,
T Tran

Tan T
Posts: 7
Joined: Mon Feb 09, 2004 7:09 pm
Contact:

Post by Tan T » Tue Feb 10, 2004 10:37 pm

Below is my code, I figured out how to save the jpgs to the windows file system, when I use the windows file system format it works using the code below

String path = "C:/Oracle/jdev/mywork/Application1/Project1/public_html/images/";
try {
ChartUtilities.saveChartAsJPEG(new File(path + Fname + Lname + Cycle + dateFormat + ".jpg"), chart, 650, 450); //width height
returnCode = Fname + Lname + Cycle + dateFormat + ".jpg";
}
catch (java.io.IOException e) {}

}


When saving my project and loading all files onto the linux box I use the linux file system format and the jpgs is not created and I get a NULL

String path = "/var/tomcat4/webapps/Application1/jsp/images";
try {
ChartUtilities.saveChartAsJPEG(new File(path + Fname + Lname + Cycle + dateFormat + ".jpg"), chart, 650, 450); //width height
returnCode = Fname + Lname + Cycle + dateFormat + ".jpg";
}
catch (java.io.IOException e) {}

}


Not sure if I am using the correct format in linux, any help appreciated
Thanks!

Taqua
JFreeReport Project Leader
Posts: 698
Joined: Fri Mar 14, 2003 3:34 pm
Contact:

Post by Taqua » Tue Feb 10, 2004 10:56 pm

Hi,

well, most systems do not run the tomcat server as user "root" for security reasons. So it could be still a permission issue. But you will never know, as you swallow the exception, without printing any log information.

Right now, your system silently smiles while you try to find the bug ... Please: Don't ignore exceptions - they all carry a message which might be important for you ;)

Have more fun,
said Thomas

Tan T
Posts: 7
Joined: Mon Feb 09, 2004 7:09 pm
Contact:

Post by Tan T » Tue Feb 10, 2004 11:01 pm

I know what you mean, this is for testing purposes. How can this be accomplished?

THanks!

Tan T
Posts: 7
Joined: Mon Feb 09, 2004 7:09 pm
Contact:

Post by Tan T » Wed Feb 11, 2004 4:55 pm

How can this be accomplished in using linux path to specifying where I want to save my jpg files?

In windows I use: C:/Oracle/jdev/mywork/Application1/Project1/public_html/images/

and it works

In linux I have some jpgs already located in the images directory, but when I creat new jpgs in my application the jpgs does not go to the path that I specified.

Thanks!
(Sorry don't mean to beat a dead horse!) :)

Taqua
JFreeReport Project Leader
Posts: 698
Joined: Fri Mar 14, 2003 3:34 pm
Contact:

Post by Taqua » Wed Feb 11, 2004 6:06 pm

Hi,

well, here comes my question: Have you checked, which exception (if any, but I guess there is one) is caught?

Please add a "e.printStackTrace()" into your "try/catch" block, or you won't see if anything goes wrong, and playing guessing games with the computer is borring - the maschine will never get bored :)

The stacktrace of that exeption would be nice too ... as it carries the hints which lead to the cause of all the trouble.

Btw. There is a trailing slash missing in your path, so that the created file might be incorrect. But you will never know without looking at the exception ;)

Have more fun,
said Thomas

Tan T
Posts: 7
Joined: Mon Feb 09, 2004 7:09 pm
Contact:

Post by Tan T » Wed Feb 11, 2004 6:28 pm

Hello,

The following is the error I get when I print the error out:

Errorjava.io.FileNotFoundException:
/var/tomcat4/webapps/Application1/jsp/images/02112004.png (No such file or directory)

HERE IS HOW I USE THE PATH IN MY CODE:

String linuxpath = "/var/tomcat4/webapps/Application1/jsp/images/"

ChartUtilities.saveChartAsPNG(new File(linuxpath + Fname + Lname + Cycle + dateFormat + ".png"), chart, 650, 450); //width height

What do you think??

Jeffh
Posts: 13
Joined: Thu Oct 09, 2003 9:47 am

Post by Jeffh » Thu Feb 12, 2004 10:28 am

This probably means one of the parent directories in your path there does not exist...

I'm guessing that images dir in /var/tomcat4/webapps/Application1/jsp probably doesn't already exist when you call new File(...).

Make sure that all your parent directories exist, or use the
mkdirs() method that is in the File class. to make the parent directories
before you call the saveChartAsPNG method.

You can try something like this:

File dirs = new File(/var/tomcat4/webapps/Application1/jsp/images);

if (! dirs.exists()) {
dirs.mkdirs();
}


Oh and you should never ignore expections completely, they are there for a reason.
Jeff

Guest

Post by Guest » Thu Feb 12, 2004 3:30 pm

Hello,

The path that I showed does exist in my linux directory. I am trying to save my files into that directory, whick is where I am getting stuck.


I didn't know it would be this difficult. :?

miker

writing files in linux

Post by miker » Wed Mar 03, 2004 2:32 pm

hi,

I encountered a similar problem and I just created an empty file :

Code: Select all

touch myfile.png
then changed permissions on that file

Code: Select all

chmod 777 myfile.png
(if that works, change it to 755 or something more sane)

Now you should be able to write. A better solution would be to change permissions on the whole dir, so non-root users can write in that dir.

Mike

Locked