在js中需要引入file的cordova包

require("cordova!cordova-plugin-file");

如果要存到手机的根目录下,在Native文件夹的对应项目中的config.xml配置文件里添加

<preference name="AndroidPersistentFileLocation" value="Compatibility"/>

参考文档:http://docs.wex5.com/cordova-plugin-file/

创建文件:

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fs) {

console.log('file system open: ' + fs.name);

fs.root.getFile("newPersistentFile.txt", { create: true, exclusive: false }, function (fileEntry) {

console.log("fileEntry is file?" + fileEntry.isFile.toString());

// fileEntry.name == 'someFile.txt'

// fileEntry.fullPath == '/someFile.txt'

writeFile(fileEntry, null);

}, onErrorCreateFile);

}, onErrorLoadFs);

写入文件

function writeFile(fileEntry, dataObj) {

// Create a FileWriter object for our FileEntry (log.txt).

fileEntry.createWriter(function (fileWriter) {

fileWriter.onwriteend = function() {

console.log("Successful file read...");

readFile(fileEntry);

};

fileWriter.onerror = function (e) {

console.log("Failed file read: " + e.toString());

};

// If data object is not passed in,

// create a new Blob instead.

if (!dataObj) {

dataObj = new Blob(['some file data'], { type: 'text/plain' });

}

fileWriter.write(dataObj);

});

}

读取文件

function readFile(fileEntry) {

fileEntry.file(function (file) {

var reader = new FileReader();

reader.onloadend = function() {

console.log("Successful file read: " + this.result);

displayFileData(fileEntry.fullPath + ": " + this.result);

};

reader.readAsText(file);

}, onErrorReadFile);

}

wex5 file文件存储的更多相关文章

  1. Android File文件存储功能

    1.介绍 2.使用方法 3.文件存储位置 4.java后台代码 package com.lucky.test47file; import android.support.v7.app.AppCompa ...

  2. Android开发--数据存储之File文件存储

    转载来自:http://blog.csdn.net/ahuier/article/details/10364757,并进行扩充 引言:Android开发中的数据存储方式 Android提供了5种方式存 ...

  3. File文件存储

    文件存储的核心是Context提供了一个openFileOutput()与openFileInput()俩个方法 课程demo public class MainActivity extends Ap ...

  4. (转)FastDFS文件存储

    一.FastDFS介绍 FastDFS开源地址:https://github.com/happyfish100 参考:分布式文件系统FastDFS设计原理 参考:FastDFS分布式文件系统 个人封装 ...

  5. Android中使用File文件进行数据存储

    Android中使用File文件进行数据存储 上一篇学到使用SharedPerences进行数据存储,接下来学习一下使用File进行存储 我们有时候可以将数据直接以文件的形式保存在设备中, 例如:文本 ...

  6. File存储 - 文件存储

    博客地址 http://www.cnblogs.com/mmyblogs/p/6107472.html(转载请保留) 文件存储 文件存储是 Android 中最基本的一种数据存储方式,它不对存储的内容 ...

  7. Android数据存储之Android 6.0运行时权限下文件存储的思考

    前言: 在我们做App开发的过程中基本上都会用到文件存储,所以文件存储对于我们来说是相当熟悉了,不过自从Android 6.0发布之后,基于运行时权限机制访问外置sdcard是需要动态申请权限,所以以 ...

  8. FILE文件流的中fopen、fread、fseek、fclose的使用

    FILE文件流用于对文件的快速操作,主要的操作函数有fopen.fseek.fread.fclose,在对文件结构比较清楚时使用这几个函数会比较快捷的得到文件中具体位置的数据,提取对我们有用的信息,满 ...

  9. app端上传文件至服务器后台,web端上传文件存储到服务器

    1.android前端发送服务器请求 在spring-mvc.xml 将过滤屏蔽(如果不屏蔽 ,文件流为空) <!-- <bean id="multipartResolver&q ...

随机推荐

  1. linux开启数据库远程连接

    1.阿里云开启数据库端口 3306 2. 修改 Mysql-Server 用户配置 mysql -uroot -p(注意此用户必须要有最高级权限才行 默认root用户) mysql> USE m ...

  2. [转]html中meta作用

    meta是html语言head区的一个辅助性标签.几乎所有的网页里,我们可以看到类似下面这段的html代码:  <head>  <meta http-equiv="cont ...

  3. cad二次开发中DBText对象的外框GeometricExtents有问题?

    CAD2007版本 acDoc.Editor.WriteMessage( string.Format("[{0:F1},{1:F1},{2:F1}] - [{3:F1},{4:F1},{5: ...

  4. golang mysql 如何设置最大连接数和最大空闲连接数

    本文介绍golang 中连接MySQL时,如何设置最大连接数和最大空闲连接数. 关于最大连接数和最大空闲连接数,是定义在golang标准库中database/sql的. 文中例子连接MySQL用的SQ ...

  5. linux 基础 文件操作

    cat -A /etc/passwdnl -ba passwd cat -A man_db.conf more man_db.conf less man_db.conf head -n 5 /var/ ...

  6. dbgrid中移动焦点到指定的行和

    dbgrid是从TCustomGrid继承下来的,它有col与row属性,只不过是protected的,不能直接访问,要处理一下,可以这样: TDrawGrid(dbgrid1).row:=row;  ...

  7. debian系统中添加sudo权限

    刚安装好的Debian默认还没有sudo功能.1.安装sudo# apt-get install sudo2.修改 /etc/sudoers 文件属性为可写# chmod +w /etc/sudoer ...

  8. postman插件的安装以及简单介绍

    1:postman是干什么的? Postman官网上这么介绍的:“Modern software is built on APIs,Postman helps you develop APIs fas ...

  9. 【经验分享】Mongodb操作类实现CRUD

    一.背景 公司项目中在做数据存储时使用到Mongodb,所以想着将Mongodb的操作封装后可供项目中其他成员方便使用. 附上Mongodb的下载地址: 下载 1.Mongodb类 此类主要是用来构造 ...

  10. php使用装饰模式无侵入式加缓存

    <?php namespace App\Services; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\ ...