2014-10-18 170 views
-2

我正在創建一個maven插件,我需要在項目目錄中寫入一個新文件。通過文件寫入文件寫入會給出AccessDeniedException異常

由於某些原因,當我嘗試創建一個新文件時,我得到了AccessDeniedException。

堆棧跟蹤:

[ERROR] Failed to execute goal org.ofx:ofx-maven-plugin:1.0-SNAPSHOT:generateScreensEnum (default) on project preloader: Execution default of goal org.ofx:ofx-maven-plugin:1.0-SNAPSHO 
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. 
[ERROR] Re-run Maven using the -X switch to enable full debug logging. 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles: 
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException 

c:\devl\work\preloader> 

這是一個沒有現有的文件,所以它不應該是一個鎖定的資源情況。 我也嘗試寫入不同的文件夾(不是項目文件夾),以防萬一,看看它是否解決它,它不。

我的代碼:

Files.write(enumLocation, lines, Charset.defaultCharset(), StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING); 

任何想法?

+1

顯示您寫的代碼將有所幫助 – 2014-10-18 16:49:24

+0

仍然沒有足夠的細節。向我們展示所有代碼,包括構建要寫入文件路徑的代碼(並告訴我們該代碼應該執行的操作以及實際執行的操作)。 – 2014-10-18 17:59:57

+0

就像這樣說,寫文件的路徑是什麼都沒有關係,我試過「c:\\ temp」,我得到了同樣的錯誤,我沒有更多要說明的,我只是想保存一個文件到磁盤上的任何位置。 – 2014-10-18 18:17:56

回答

0

發現問題,如果文件不存在,需要添加StandardOpenOption.WRITE,選項。

Files.write(enumLocation, lines, Charset.defaultCharset(), StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);