MATLAB: How to use java.nio in MATLAB filejavanio How to delete a file using this method in MATLAB? https://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#delete(java.nio.file.Path) like this, but using NIO instead of IO: java.io.File(filename).delete() Best Answer Here is two example of deleting a file using java.nio.file.%% Method1str = fullfile(pwd, 'test1.txt' );%jpath1 = java.nio.file.Paths.get(str) % not worksjpath1 = java.nio.file.Paths.get(str, javaArray('java.lang.String', 0)); % worksjava.nio.file.Files.delete(jpath1)%% Method2jpath2 = java.nio.file.Paths.get(pwd, 'test2.txt');java.nio.file.Files.delete(jpath2)I've tested in MATLAB R2018b on Windows 10.As you may know, from R2017b, MATLAB's JVM was changed to Java 8. So, java.nio.file.Files.delete used in MATLAB R2017b ~ R2018b is that of Java 8.https://docs.oracle.com/javase/8/docs/api/java/nio/file/Files.html#delete-java.nio.file.Path- Related SolutionsMATLAB: Do I get a “java.lang.IllegalArgumentException” error message when starting MATLAB on OS X This is not a bug, but a system conflict.The solution is to delete the xerces.jar file in /Library/Java/Extensions. MATLAB: How to reiterate the function automatically if the code stops working because the internet disconnected How does this code stop? With an error message? Then TRY-CATCH is a direct solution:success = false;while ~success try xdom = xmlread('...'); success = true; catch ME disp('Failed:'); disp(ME.message); pause(30); endend Related QuestionError when trying to run deploytool in console with no display
Best Answer