I want to use the java.nio.file.Files.move()
method in Matlab.
Although I only need the default behavior, Matlab requires all 3 inputs or would throw the No method ... with matching signature found.
error. Passing []
(which I think gets converted to null
though not documented) gets the java.lang.NullPointerException
error.
How do I make an CopyOption
object in Matlab?
Example:
>> version -java
ans =
'Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
zipFilePath=java.nio.file.Paths.get('test.zip',javaArray('java.lang.String', 0));
zipFileSystem=java.nio.file.FileSystems.newFileSystem(zipFilePath,[]);
path1=zipFileSystem.getPath('/test.txt',javaArray('java.lang.String', 0));
path2=zipFileSystem.getPath('/test_changed.txt',javaArray('java.lang.String', 0));
% java.nio.file.Files.move(path1,path2,???); % what should ??? be..
java.nio.file.Files.move(path1,path2,java.nio.file.StandardCopyOption.COPY_ATTRIBUTES)
No method 'java.nio.file.Files.move' with matching signature found.
zipFileSystem.close();
(I am also attaching my particular use of .move()
in case there is something else that matters but I don't know.)
CodePudding user response:
The third parameter to Files.move is an array of java.nio.file.CopyOption
, so you'd need to set up an array of CopyOption
initialised with one entry for the value of the implementing class java.nio.file.StandardCopyOption.COPY_ATTRIBUTES
:
optArr = javaArray('java.nio.file.CopyOption',1);
optArr(1) = java.nio.file.StandardCopyOption.COPY_ATTRIBUTES;
java.nio.file.Files.move(path1, path2, optArr);