javascript 如何使用phonegap将文件从一个文件夹移动/复制到android中的另一个文件夹?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12418901/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 16:09:17  来源:igfitidea点击:

How to move/copy a file from one folder to other folder in android using phonegap?

javascriptandroidhtmlcordova

提问by android phonegap

In my application on button click i am able to download a file from url into my SDCARD of android whose path is something like "mnt/sdcard/files/data.pdf"and now i want to move/copy this file to some other destination folder using phonegap. Can anyone please help me how to do this in phonegap?

在我单击按钮的应用程序中,我可以将文件从 url 下载到我的 android SDCARD 中,其路径类似于“mnt/sdcard/files/data.pdf”,现在我想将此文件移动/复制到其他目的地使用 phonegap 的文件夹。任何人都可以帮助我如何在phonegap中做到这一点吗?

I have a pdf file in path "mnt/sdcard/files/data.pdf"and i want to move that pdf file to new path "mnt/sdcard/download/data.pdf"anyone please help me.

我在路径“mnt/sdcard/files/data.pdf”中有一个pdf文件,我想将该pdf文件移动到新路径“mnt/sdcard/download/data.pdf”,请帮助我。

回答by pedrofurla

Assuming you are actually using Cordova, check FileEntry, which has methods named moveToand copyTo.

假设您实际上使用的是 Cordova,请检查FileEntry,它具有名为moveTo和 的方法copyTo

Be aware that the file systems API are a callback hell.

请注意,文件系统 API 是回调地狱。

One quick example from the docs cooked overlooking the docs:

一个来自煮熟的文档的快速示例,可以俯瞰文档:

var fail = function(err) { console.log(err) }
window.resolveLocalFileSystemURI("file:///example.txt", function(file) {
   window.resolveLocalFileSystemURI("file:///directory-to-move-to", function(destination) {
             file.moveTo(destination,"example.txt");
   },fail)
},fail);

I skipped the error handling functions for clearness, suppose it works without it.

为了清楚起见,我跳过了错误处理函数,假设没有它也能工作。