Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





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.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-24-2007, 05:45 AM
Member
 
Join Date: Dec 2007
Posts: 2
vikain is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-02-2008, 04:21 AM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 839
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
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.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-02-2008, 05:00 AM
Member
 
Join Date: Dec 2007
Posts: 2
vikain is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-02-2008, 05:06 AM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 839
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
Quote:
Originally Posted by vikain View Post
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.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-02-2008, 05:37 AM
simi's Avatar
Member
 
Join Date: Dec 2007
Location: Singapore
Posts: 18
simi is on a distinguished road
Send a message via Yahoo to simi
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
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 01-02-2008, 05:38 AM
simi's Avatar
Member
 
Join Date: Dec 2007
Location: Singapore
Posts: 18
simi is on a distinguished road
Send a message via Yahoo to simi
Hi,

Sorry i forgot to refresh the page before posting my reply.
glad that you already solved it.

all the best.
Regards,
Simi
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Software caused connection abort: socket write error kuguy Networking 2 05-21-2008 07:29 AM
Write unicode into file vata2999 New To Java 1 08-08-2007 04:04 PM
Help with write file in java mathias New To Java 1 07-31-2007 07:51 PM
how to write onto a file mirage_87 New To Java 0 07-21-2007 11:26 AM
Struts tag error with bean:write sandor Web Frameworks 1 04-07-2007 05:50 AM


All times are GMT +3. The time now is 07:13 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org