フィルターのクリア

How to use java.nio in MATLAB?

2 ビュー (過去 30 日間)
bbb_bbb
bbb_bbb 2018 年 12 月 26 日
コメント済み: bbb_bbb 2018 年 12 月 30 日
How to delete a file using this method in MATLAB?
like this, but using NIO instead of IO:
java.io.File(filename).delete()

採用された回答

Kojiro Saito
Kojiro Saito 2018 年 12 月 27 日
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
java.nio.file.Files.delete(jpath1)
%% Method2
jpath2 = 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.
  4 件のコメント
Kojiro Saito
Kojiro Saito 2018 年 12 月 29 日
>> Btw, how to determine the success of the operation:
I would simply use "try catch".
try
java.nio.file.Files.delete(jpath2)
catch ME
% When delete was failed, do some error handle
error(ME.message)
end
% When delete was successful
msgbox('Successfully deleted')
bbb_bbb
bbb_bbb 2018 年 12 月 30 日
ME.message - gives error...

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCall Java from MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by