|
|
Welcome to the Java Forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:
- have access to post topics
- communicate privately with other members (PM)
- not see advertisements between posts
- have the possibility to earn one of our surprises if you are an active member
- access many other special features that will be introduced later.
Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact us.
|
|

12-24-2007, 05:45 AM
|
|
Member
|
|
Join Date: Dec 2007
Posts: 2
|
|
|
File Write Error
I am trying to write a chart to the desktop of the current user. While the following piece of code is able to generate the directory, the JFreeChart is failing to write the chart to the location. could anyone please point me to a solution for this problem?
public void saveChartAsJpeg() throws IOException
{
String userDesktop = System.getProperty("user.home") + "\\Desktop\\";
new File(userDesktop + "\\Reports\\").mkdirs();
ChartUtilities.saveChartAsJPEG(new File(userDesktop + "\\Reports"), constructChart(), 250, 250);
}
When I run this in main(), I get this following exception:
Exception in thread "main" java.io.FileNotFoundException: C:\Documents and Settings\vikain\Desktop\Reports (Access is denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.j ava:179)
at java.io.FileOutputStream.<init>(FileOutputStream.j ava:131)
at org.jfree.chart.ChartUtilities.saveChartAsJPEG(Cha rtUtilities.java:503)
at org.jfree.chart.ChartUtilities.saveChartAsJPEG(Cha rtUtilities.java:457)
at edu.sjsu.dfl.backend.JFreeChartPieDemo.saveChartAs Jpeg(JFreeChartPieDemo.java:37)
at edu.sjsu.dfl.backend.JFreeChartPieDemo.main(JFreeC hartPieDemo.java:41)
I am sure that this is with the file write permissions but have no clue as to where I should make changes.
Thanks.
|
|

01-02-2008, 04:21 AM
|
 |
Moderator
|
|
Join Date: Dec 2007
Location: NewEngland, US
Posts: 839
|
|
|
I would wager to guess that it is in fact a permissions issue, as the error message tells you. Code looks okay... but I'm not familiar with the Chart package you're using. Maybe someone could provide more info on this... vikain, have you figured it out by now? Either way, I'd like to hear about it. If you're using Windows, then I imagine to make permission changes you need to be Administrator and/or give the current user permissions... this is more of a technical problem I think rather than a Java specific issue.. no?
Last edited by CaptainMorgan : 01-02-2008 at 04:24 AM.
|
|

01-02-2008, 05:00 AM
|
|
Member
|
|
Join Date: Dec 2007
Posts: 2
|
|
|
Apologies for my insolent lack of responsibility to keep my post updated. But I found the root cause for the exception that I mentioned. It is not with the file permissions as I, somewhere in my mind, guessed with a positive skepticism but dismissed the thought as soon as it struck me. I was able to create the "Reports" directory but failed while saving the chart. Infact, it was bound to fail as I didn't give the name to the chart!. So here is the solution for it, in case any one may find it useful:
public void saveChartAsJpeg() throws IOException
{
String userDesktop = System.getProperty("user.home") + "\\Desktop\\";
new File(userDesktop + "\\Reports\\").mkdirs();
ChartUtilities.saveChartAsJPEG(new File(userDesktop + "\\Reports\\ChartName.jpg"), constructChart(), 250, 250);
}
Thank you.
|
|

01-02-2008, 05:06 AM
|
 |
Moderator
|
|
Join Date: Dec 2007
Location: NewEngland, US
Posts: 839
|
|
Originally Posted by vikain
Apologies for my insolent lack of responsibility to keep my post updated. But I found the root cause for the exception that I mentioned. It is not with the file permissions as I, somewhere in my mind, guessed with a positive skepticism but dismissed the thought as soon as it struck me. I was able to create the "Reports" directory but failed while saving the chart. Infact, it was bound to fail as I didn't give the name to the chart!. So here is the solution for it, in case any one may find it useful:
public void saveChartAsJpeg() throws IOException
{
String userDesktop = System.getProperty("user.home") + "\\Desktop\\";
new File(userDesktop + "\\Reports\\").mkdirs();
ChartUtilities.saveChartAsJPEG(new File(userDesktop + "\\Reports\\ChartName.jpg"), constructChart(), 250, 250);
}
Thank you.
Excellent, glad you solved your problem.
|
|

01-02-2008, 05:37 AM
|
 |
Member
|
|
Join Date: Dec 2007
Location: Singapore
Posts: 18
|
|
|
Hi Vikain,
ChartUtilities.saveChartAsJPEG(new File(userDesktop + "\\Reports"), constructChart(), 250, 250);
you need to update above line of code to provide file name. currently you are specifying only directory "Reports" but you need to give file name eg. reports.jpg
Regards,
Simi
|
|

01-02-2008, 05:38 AM
|
 |
Member
|
|
Join Date: Dec 2007
Location: Singapore
Posts: 18
|
|
|
Hi,
Sorry i forgot to refresh the page before posting my reply.
glad that you already solved it.
all the best.
Regards,
Simi
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|