Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java [写入扩展属性时出错]可以';t在/tmp目录之外时写入扩展属性_Java_Nio - Fatal编程技术网

Java [写入扩展属性时出错]可以';t在/tmp目录之外时写入扩展属性

Java [写入扩展属性时出错]可以';t在/tmp目录之外时写入扩展属性,java,nio,Java,Nio,我正在尝试将UserDefinedFileAttribute写入文件 UserDefinedFileAttributeView view = Files.getFileAttributeView(myFile,UserDefinedFileAttributeView.class); view.write("myattibute",Charset.defaultCharset().encode("1234"); 我确保文件权限是正确的。然而,当这段代码在UNIX上运行时,我得到了一个错误 写入

我正在尝试将
UserDefinedFileAttribute
写入文件

UserDefinedFileAttributeView view = Files.getFileAttributeView(myFile,UserDefinedFileAttributeView.class);

view.write("myattibute",Charset.defaultCharset().encode("1234");
我确保文件权限是正确的。然而,当这段代码在UNIX上运行时,我得到了一个错误

写入扩展属性时出错:不支持操作


但是,如果我更新/tmp目录中的文件,它就可以工作了?

我不太确定您在寻找什么,但在Windows中,它可以工作(对我来说,也许对您也可以):

使用JUnit测试:

@Test
public void B_getFileInfo(){
    String filepath = "....your.File";
    METAdao.writeCustomMETAfile(filepath,"test","true");
    String[] attribList = METAdao.readCustomMETAfile(filepath);
    String[] expected1 = {"test"};
    assertArrayEquals(expected1, attribList);
    String test = METAdao.readCustomMETAfile(filepath,"test");
    assertEquals("true", test);
    METAdao.deleteCustomMETAfile(filepath,"test");
    String[] recheck = METAdao.readCustomMETAfile(filepath);
    String[] expected2 = {};
    assertArrayEquals(expected2, recheck);
}

您可能试图将扩展属性写入不支持它的文件系统。在这种情况下,Java错误地为
UserDefinedFileAttributeView
返回非
null
,尽管这会导致客户端代码认为它可以工作

@Test
public void B_getFileInfo(){
    String filepath = "....your.File";
    METAdao.writeCustomMETAfile(filepath,"test","true");
    String[] attribList = METAdao.readCustomMETAfile(filepath);
    String[] expected1 = {"test"};
    assertArrayEquals(expected1, attribList);
    String test = METAdao.readCustomMETAfile(filepath,"test");
    assertEquals("true", test);
    METAdao.deleteCustomMETAfile(filepath,"test");
    String[] recheck = METAdao.readCustomMETAfile(filepath);
    String[] expected2 = {};
    assertArrayEquals(expected2, recheck);
}