Results 1 to 6 of 6
  1. #1
    vikain is offline Member
    Join Date
    Dec 2007
    Posts
    2
    Rep Power
    0

    Default 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.

  2. #2
    CaptainMorgan's Avatar
    CaptainMorgan is offline Moderator
    Join Date
    Dec 2007
    Location
    NewEngland, US
    Posts
    835
    Rep Power
    9

    Default

    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.

  3. #3
    vikain is offline Member
    Join Date
    Dec 2007
    Posts
    2
    Rep Power
    0

    Default

    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.

  4. #4
    CaptainMorgan's Avatar
    CaptainMorgan is offline Moderator
    Join Date
    Dec 2007
    Location
    NewEngland, US
    Posts
    835
    Rep Power
    9

    Default

    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.

  5. #5
    simi's Avatar
    simi is offline Member
    Join Date
    Dec 2007
    Location
    Singapore
    Posts
    18
    Rep Power
    0

    Default

    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

  6. #6
    simi's Avatar
    simi is offline Member
    Join Date
    Dec 2007
    Location
    Singapore
    Posts
    18
    Rep Power
    0

    Default

    Hi,

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

    all the best.
    Regards,
    Simi

Similar Threads

  1. Replies: 3
    Last Post: 04-13-2010, 04:43 PM
  2. how to write onto a file
    By mirage_87 in forum New To Java
    Replies: 6
    Last Post: 09-08-2009, 04:54 PM
  3. Write unicode into file
    By vata2999 in forum New To Java
    Replies: 1
    Last Post: 08-08-2007, 04:04 PM
  4. Help with write file in java
    By mathias in forum New To Java
    Replies: 1
    Last Post: 07-31-2007, 07:51 PM
  5. Struts tag error with bean:write
    By sandor in forum Web Frameworks
    Replies: 1
    Last Post: 04-07-2007, 05:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •