简体   繁体   English

拥有权限时出现权限被拒绝的错误

[英]Getting a permission denied error when I have permission

I'm writing an excel spreadsheet file (.xls) to a directory to which I have permission, xlsOutput is a directory I made at the root of my project with full permission (right click directory>properties>resource?rwx for all three groups (owner, group, other) 我正在将excel电子表格文件(.xls)写入我具有权限的目录,xlsOutput是我在项目根目录下创建的具有完全权限的目录(对于所有三个组,右键单击目录>属性>资源?rwx (所有者,组,其他)

however I'm getting the flowing stack trace: 但是我得到了流动的堆栈跟踪:

java.io.FileNotFoundException: /xlsOutput (Permission denied)
    at java.io.FileOutputStream.open(Native Method)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:194)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:145)
    at jxl.Workbook.createWorkbook(Workbook.java:301)
    at jxl.Workbook.createWorkbook(Workbook.java:286)
    at com.generalatomics.ctg.taxengine.automation.tools.testhelper.writers.ExcelTemplateWriter.write(ExcelTemplateWriter.java:33)
    at com.generalatomics.ctg.taxengine.automation.tools.testhelper.TestClasses.testXMLToXLS(TestClasses.java:32)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
    at org.testng.TestRunner.privateRun(TestRunner.java:767)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
    at org.testng.TestNG.run(TestNG.java:1057)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

Not sure why I can't write to this directory? 不知道为什么我不能写这个目录? Am I missing something obvious? 我是否缺少明显的东西? I feel like I am. 我觉得我是。 Any help or assistance would be much appreciated, thanks. 任何帮助或协助将不胜感激,谢谢。

Edit: 编辑:

@Test
public void testXMLToXLS() throws Exception {
    ITemplateGenerator tGen = new CalcTemplateGenerator();
    TestTemplate template = tGen.generateTemplate("xmlDir");
    ITemplateWriter writer = new ExcelTemplateWriter();

    String file = "/xlsOutput";
    File f = new File(file);
    logger.debug("Can write: "+f.canWrite()); // returns false but why??
    writer.write(template, file);
}

public void write ( TestTemplate template , String path ) throws Exception {

    CellFormat formatHeaders = new WritableCellFormat( new WritableFont( WritableFont.createFont("Calibri"), 12,  WritableFont.BOLD ) );
    CellFormat formatText = new WritableCellFormat( new WritableFont( WritableFont.createFont("Calibri"), 12,  WritableFont.NO_BOLD ) );

    // Create workbook object at the specified path (output directory)
    WritableWorkbook workbook = Workbook.createWorkbook( new File ( path));

    // Create a spreadhseet with name of topic and the index number at which to insert
    WritableSheet sheet = workbook.createSheet( template.getTopic(), 0) ;
    ...etc
} 

Edit: 编辑:

Figured it out.... 弄清楚了....

String file = "xlsOutput/testFile.xls"; 字符串文件=“ xlsOutput / testFile.xls”;

I should not have included "/" in front of the directory...stupid mistake. 我不应该在目录前面包含“ /” ...这是愚蠢的错误。 Thanks everyone for helping 谢谢大家的帮助

You supplied an absolute file system path, /xlsOutput , one beginning with a / . 您提供了一个绝对文件系统路径/xlsOutput ,以/开头。 If you were to omit the leading `/', the JRE would interpret that as being relative to the system property user.home which would likely be the directory your project. 如果您要省略前导的“ /”,JRE会将其解释为相对于系统属性user.home而言 ,后者可能是您的项目目录。 Try that. 试试看

我通过添加“ /” @ immibis犯了一个愚蠢的错误,谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将映像上传到服务器时权限被拒绝错误 - Permission denied error when uploading image to server 尝试以myuser身份运行作业时,权限被拒绝,但错误显示root用户没有足够的权限 - Permission denied when trying to run a job as myuser, but error says root doesn't have enough permissions 获取SecurityException:Java中的权限被拒绝 - Getting a SecurityException: Permission denied in java java.io.FileNotFoundException :(我拒绝访问该文件时) - java.io.FileNotFoundException: (Access is denied) when i have permission to the file 尝试从图片读取元数据时获取FileNotFoundException(权限被拒绝) - Getting FileNotFoundException (Permission denied) when trying to read metadata from a picture 获取随机权限从ExternalFilesDir访问时拒绝错误 - Getting random Permission Denied errors when accessing from ExternalFilesDir 获取权限被拒绝(公钥)。 在AWS上启动hadoop集群时 - Getting Permission denied (publickey). when starting hadoop cluster on AWS 读取文件时,Java中的权限被拒绝(Linux) - Getting permission denied in Java when reading a file (Linux) 为什么我得到JDBC和Netbeans的许可被拒绝? - Why am I getting a permission denied with JDBC and Netbeans? 为什么我的Firestore数据被拒绝? - Why am I getting permission denied to my Firestore data?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM