Results 1 to 6 of 6
Thread: File Write Error
- 12-24-2007, 04:45 AM #1
Member
- Join Date
- Dec 2007
- Posts
- 2
- Rep Power
- 0
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, 03:21 AM #2
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 03:24 AM.
- 01-02-2008, 04:00 AM #3
Member
- Join Date
- Dec 2007
- Posts
- 2
- Rep Power
- 0
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, 04:06 AM #4
- 01-02-2008, 04:37 AM #5
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, 04:38 AM #6
Similar Threads
-
Software caused connection abort: socket write error
By kuguy in forum NetworkingReplies: 3Last Post: 04-13-2010, 03:43 PM -
how to write onto a file
By mirage_87 in forum New To JavaReplies: 6Last Post: 09-08-2009, 03:54 PM -
Write unicode into file
By vata2999 in forum New To JavaReplies: 1Last Post: 08-08-2007, 03:04 PM -
Help with write file in java
By mathias in forum New To JavaReplies: 1Last Post: 07-31-2007, 06:51 PM -
Struts tag error with bean:write
By sandor in forum Web FrameworksReplies: 1Last Post: 04-07-2007, 04:50 AM


LinkBack URL
About LinkBacks


Bookmarks