I m accessing file from java applicatio开发者_开发百科n, but i m getting following exception
c:\Program Files\sample\sample\cample.xml (Acc?s refus?) at java.io.FileOutputStream.(Unknown Source) at java.io.FileOutputStream. at java.awt.event.InvocationEvent.dispatch(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source)
is any body have any idea why this exception occurred .....,solution for this..... is it related to file permission means file have not read permission.
With my limited knowledge of French, I think "Acc?s refus?" is, on your system, "Accès refusé?" or something similar. Which means: "access denied". In other words, your Java program is not allowed to go to the location you mention.
Considering that the location is under c:\program files
, this location is indeed forbidden for Windows Vista and later. It is better to choose a location under %APPDATA%
or elsewhere where you have writing access.
Note that Windows tries to prevent writing to delicate locations for security reasons. Even if you gain the right by changing your account to Administrator, you still should not put data, settings, files etc under Program Files. Instead, it should go under the current user's, or the default user's application data directory. In Java you can get this path as follows:
// get application path
System.getenv("APPDATA");
This exception means that the account you are running your application under doesn't have write permissions to the file. You will need to grant the necessary permissions to the file you are trying to write to. Another option is to put the file into another folder where you you have the necessary permissions.
精彩评论