在我的Flutter Mac应用程序中添加沙盒功能之后,无法重命名/移动文件

问题描述 投票:0回答:1

代码块:

 String originalPath = '/Users/dhavalkansara/Library/Containers/com.myapp.apps/Data/Library/Caches/encryption-decryption/dummy copy 8.pdf.txt';
    String newPath = '/Users/dhavalkansara/Documents/dummy copy 8.pdf';

  try {
     File file = File(originalPath);
     await file.rename(newPath);
     print('File moved successfully');
  } catch (e) {
    print('Error: $e');
  }

eRror:

快报:错误:PathaccessException:无法将文件重命名为 '/users/dhavalkansara/documents/dummy copy 8.pdf',path = '/users/dhavalkansara/library/containers/com.myapp.apps/data/library/caches/cencryption-decryptimption/dummy 复制8.pdf.txt'(OS错误:不允许操作,ERRNO = 1)

我具有应用沙盒功能的设置:

enter image description here

ios flutter macos dart appstore-sandbox
1个回答
0
投票

Import'Dart:io';

void movefile()async { 字符串原始路径='/users/dhavalkansara/library/containers/com.myapp.apps/data/library/caches/encryption-decryption/dummy/dummy copy 8.pdf.txt'; 字符串newPath ='/users/dhavalkansara/documents/dummy copy 8.pdf';

try {

File file = File(originalPath); // Copy the file first, then delete the original. await file.copy(newPath); await file.delete(); print('File moved successfully'); } catch (e) { print('Error: $e'); }
}

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.