1、 使用以下函数,将文件A 拷贝为文件B
'''’function copyFile(fileCopyInfo) {
//console.log("fileFrom:" + fileCopyInfo.fileFrom );
plus.io.requestFileSystem( plus.io.PRIVATE_DOC, function(fs){
// fs.root是根目录操作对象DirectoryEntry
fs.root.getFile(fileCopyInfo.fileFrom,{create:false}, function(fileEntry){
fs.root.getDirectory("uniapp_save",{create:true,exclusive:false}, function(fileEntry1){
fileEntry.copyTo( fileEntry1, "123.pdf", function( entry ){
typeof fileCopyInfo.success == "function" && fileCopyInfo.success();
}, e=>{typeof fileCopyInfo.faild == "function" && fileCopyInfo.faild(e);});
}, e=>{typeof fileCopyInfo.faild == "function" && fileCopyInfo.faild(e);});
}, e=>{typeof fileCopyInfo.faild == "function" && fileCopyInfo.faild(e);});
}, e=>{typeof fileCopyInfo.faild == "function" && fileCopyInfo.faild(e);});
}'''
- 使用该函数打开已拷贝好的文件B, 该函数存在于 fileCopyInfo结构success回调中执行, PDF文件被直接打开
'''uni.openDocument({
filePath: "_doc/uniapp_save/123.pdf"
fail: () => {
uni.showToast({
title: "文件打开失败",
duration: 2000
});
}
});'''
0 个回复