MATLAB Answers

How to use java.nio in MATLAB?

3 views (last 30 days)
bbb_bbb on 26 Dec 2018
Commented: bbb_bbb on 30 Dec 2018
How to delete a file using this method in MATLAB?
like this, but using NIO instead of IO:

Accepted Answer

Kojiro Saito
Kojiro Saito on 27 Dec 2018
Here is two example of deleting a file using java.nio.file.
%% Method1
str = fullfile(pwd, 'test1.txt' );
%jpath1 = java.nio.file.Paths.get(str) % not works
jpath1 = java.nio.file.Paths.get(str, javaArray('java.lang.String', 0)); % works
%% Method2
jpath2 = java.nio.file.Paths.get(pwd, 'test2.txt');
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.
bbb_bbb on 30 Dec 2018
ME.message - gives error...

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by