简体   繁体   English

如何将数组复制到phonegap中的文件?

[英]How to copy array into file in phonegap?

I have array of images as follows: 我的图像数组如下:

var imageArray = new Array(10);

function onCameraPicSuccess (imgData)  {
  imageArray.push("data:image/jpeg;base64," + imgData);
}

I am copying captured images into this array. 我将捕获的图像复制到此数组中。

Now how to copy this array into file? 现在如何将此数组复制到文件中? I am using phonegap. 我正在使用phonegap。 I want to copy into particular folder like myPhotos in my local place. 我想在我当地的地方复制到像myPhotos这样的特定文件夹。 Any help? 有帮助吗?

Is it possible to do it in javascript? 可以在javascript中执行吗? Or should i call JAVA applet from javascript to write into file? 或者我应该从javascript调用JAVA applet写入文件?

You can use the FileWriter API to write a string version of your data to the disk. 您可以使用FileWriter API将数据的字符串版本写入磁盘。

Quick Example 快速示例

function win(writer) {
    writer.onwrite = function(evt) {
        console.log("write success");
    };
    writer.write(JSON.stringify(imageArray));
};

var fail = function(evt) {
    console.log(error.code);
};

entry.createWriter(win, fail);

For the whole context, see the Full Example under the FileWriter API here . 对于整个背景下,看到的FileWriter API下的完整的例子在这里

You can use the FileReader API to read data back. 您可以使用FileReader API读取数据。 Remember to call JSON.parse to turn it back to a JavaScript object. 记得调用JSON.parse将其转回JavaScript对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM