Results 1 to 6 of 6
- 03-17-2011, 06:44 PM #1
Member
- Join Date
- Dec 2010
- Posts
- 10
- Rep Power
- 0
Access is denied when trying to create a file.
This is something I think has happened to me before when I was learning Java however I didnt take notice of it as it worked on my uni computer but on my home computer running windows 7 I get the following error message when trying to make a file:
The file im making is a JPEG which is created from the JFreeChart class:java.io.FileNotFoundException: C:\Users\James\Desktop\Measurements\1Mar (Access is denied)
Failed to make JPEG
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at org.jfree.chart.ChartUtilities.saveChartAsJPEG(Cha rtUtilities.java:520)
at org.jfree.chart.ChartUtilities.saveChartAsJPEG(Cha rtUtilities.java:474)
at dataProcessing.Analysis.plotMap(Analysis.java:118)
at dataProcessing.Analysis.main(Analysis.java:142)
The class I made to run it is (I very much doubt the problem is here either):Java Code:public static void saveChartAsJPEG(File file, JFreeChart chart, int width, int height, ChartRenderingInfo info) throws IOException { if (file == null) { throw new IllegalArgumentException("Null 'file' argument."); } if (chart == null) { throw new IllegalArgumentException("Null 'chart' argument."); } OutputStream out = new BufferedOutputStream(new FileOutputStream(file)); try { writeChartAsJPEG(out, chart, width, height, info); } finally { out.close(); } }
Has anyone experienced this?Java Code:public static void plotMap(Map<String, DataSet> dataMap, String title, String saveLocation){ Iterator<String> it = dataMap.keySet().iterator(); DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); while(it.hasNext()){ String key = it.next().toString(); DataSet data = dataMap.get(key); dataSet.addValue(data.avgRSSI(), "test", key); } JFreeChart chart=createChart(dataSet, title); File image = new File(saveLocation); try { ChartUtilities.saveChartAsJPEG(image, chart, 500, 300); } catch (IOException e) { e.printStackTrace(); System.out.println("Failed to make JPEG"); } }
Is there any way around it?
I need to make a tonne of graphs for a mountain of data I have to sift through for a 3rd year physics group project and I fear I've hit a brick wall here :confused:
If there isn't a way around it can anyone recommend another way of getting the graphs done?
- 03-18-2011, 10:11 AM #2
Member
- Join Date
- Dec 2010
- Posts
- 10
- Rep Power
- 0
I ran a test class and this has nothing to do with my code, I can't write a file and thats it.
This gives the exact same error as before:Java Code:import java.io.BufferedWriter; import java.io.FileWriter; import java.io.File; import java.io.Writer; import java.io.FileNotFoundException; import java.io.IOException; public class TestClass2 { public static void main(String[] args) { Writer writer = null; try { String text = "This is a text file"; File file = new File("C:\\write.txt"); writer = new BufferedWriter(new FileWriter(file)); writer.write(text); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { if (writer != null) { writer.close(); } } catch (IOException e) { e.printStackTrace(); } } } }
I'm running windows 7, I haven't done anything out of the ordinary or knowingly done anything that would affect this.java.io.FileNotFoundException: C:\write.txt (Access is denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileWriter.<init>(Unknown Source)
at dataProcessing.TestClass2.main(TestClass2.java:18)
Does anyone have any idea why it wont write files to my computer?
Surely this isnt unheard of?
- 03-18-2011, 10:51 AM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,400
- Blog Entries
- 7
- Rep Power
- 17
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 03-18-2011, 01:39 PM #4
Member
- Join Date
- Dec 2010
- Posts
- 10
- Rep Power
- 0
Its my personal computer and I am the only user, I have 'full control' in the permissions for all folders, I can do what I want when not using Java.
Thats what I don't understand, its my computer, why cant eclipse write files to it?
I could make the file myself in that folder, but I cant do it in Java.
I ran this:
And it fails yet as you can see I have the permissions to do things in the folder:Java Code:public static void main(String[] args) { try { AccessController.checkPermission(new FilePermission("C:\\Users\\James\\Desktop\\Measurements\\", "read,write")); System.out.println("success?"); // Has permission } catch (SecurityException e) { System.out.println("failure :("); // Does not have permission }
Last edited by adwodon; 03-18-2011 at 01:43 PM.
- 03-18-2011, 02:52 PM #5
Member
- Join Date
- Dec 2010
- Posts
- 10
- Rep Power
- 0
Someone has saved the day :)
I need to have the file location with \\ at the end
so it would be:
I guess its a windows 7 thing?Java Code:File file = new File("C:\\write.txt\\");
- 03-18-2011, 02:58 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,400
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Jni registry 'access denied' error.
By durino13 in forum Advanced JavaReplies: 4Last Post: 09-17-2011, 07:06 AM -
java.io.FileNotFoundException: ..\log\server.log (Access is denied.
By parimal in forum Advanced JavaReplies: 22Last Post: 04-09-2011, 04:59 AM -
Getting access denied error while importing file using input type="file" with IE7
By sarang1 in forum Advanced JavaReplies: 6Last Post: 02-10-2011, 09:55 AM -
Access is denied
By tholland in forum New To JavaReplies: 2Last Post: 12-20-2010, 08:57 PM -
access denied
By Dennis in forum Advanced JavaReplies: 8Last Post: 06-05-2010, 08:46 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks