-
2021-06-22 23:21:27
plus.io.resolveLocalFileSystemURL("/storage/emulated/0/baby/F7KA9H1WKBZMUMPGUHYJ",
function(entry) {
var directoryReader = entry.createReader(); //获取读取目录对象
directoryReader.readEntries(function(entries) { //历遍子目录即可.
entries.getMetadata(function(metadata) {
plus.console.log("Last Modified: " + metadata.modificationTime);
}, function() {
alert(e.message);
});
// var entries_con = [];
// var i;
// for (i = 0; i < entries.length; i++) {
// var fileExtension = entries[i].name.substring(entries[i].name.lastIndexOf('.') + 1);
// entries_con.push({
// 'name': entries[i].name,
// 'fullPath': entries[i].fullPath,
// "suffix_type": fileExtension
// })
// }
// console.log(entries_con)
},
function(err) {
console.log("访问目录失败");
}
);
},
function(err) {
console.log("访问指定目录失败:" + err.message);
}
)
这个方法可以获取到但是我正在研究怎么获取文件时间,我用安卓原生的方式可以获取到时间
更多相关内容 -
uni读取本地JSON数据文件
2020-12-19 13:48:09文件后缀为.json类型非H5端,这种类型的文件目前只能用require进行导入,导入后为一个对象类型let mapDataCollection = require('@/static/mapData/guizhou.json');console.log("cityJson: " + JSON.stringify...对于json数据分为两种情况
1. 文件后缀为.json类型
非H5端,这种类型的文件目前只能用require进行导入,导入后为一个对象类型
let mapDataCollection = require('@/static/mapData/guizhou.json');
console.log("cityJson: " + JSON.stringify(cityJson));
//=>cityJson: [{"name":"基础底图","isDown":true,"isZip":false,"isDowning":false,"update":false},...,{"name":"沿河县","isDown":false,"isZip":false,"isDowning":false,"update":false}]
H5端可以引入jq,用jq的AJAX读取本地的json文件
$.getJSON('../static/mapData/guizhou.json').then(mapdata=> {
console.log("cityJson: " + JSON.stringify(cityJson));
})
//=>cityJson: [{"name":"基础底图","isDown":true,"isZip":false,"isDowning":false,"update":false},...,{"name":"沿河县","isDown":false,"isZip":false,"isDowning":false,"update":false}]
2. 文件后缀为.js类型
可以在js文件将json用export导入,在需要的页面用import进行导入,import无法导入.json文件
//js数据文件
let cityJson = [{"name":"基础底图","isDown":true,"isZip":false,"isDowning":false,"update":false},...,{"name":"沿河县","isDown":false,"isZip":false,"isDowning":false,"update":false}]
export {
cityJson
}
//业务页面
import {cityJson} from '@/static/mapData/guizhou.js'
注意事项
uni.request是无法读取本地的.js文件和.json文件的,jq是都能读取的,但是jq只能在H5端引入使用,要注意这点
-
uni-app怎么获取本地文件目录
2020-12-19 13:48:14function fileport() { $('.mui-content').find('.Pegam').remove() var filest = document.getElementById('file').files[0]; let bianb = filest.name.... 但是在uni中又什么方法可以直接获取到。请官方大人明察function fileport() {
$('.mui-content').find('.Pegam').remove()
var filest = document.getElementById('file').files[0];
let bianb = filest.name.substring(filest.name.length - 3).toLowerCase();
let panduan = ['jpg', 'png', 'pdf', 'jpeg'];
for(let i = 0; i < panduan.length; i++) {
if(bianb == panduan[i]) {
mui.toast('上传成功')
$('.noneshuju').hide()
$('.clicbas').show()
let pop = '
'
$('.mui-content').append(pop)
$('.mui-content').css('margin-bottom', '40px')
return
} else {
mui.toast('上传失败')
return
}
}
}
这是mui里的。
但是在uni中又什么方法可以直接获取到。请官方大人明察
-
读取本地JSON文件并显示
2020-12-19 13:48:07程序功能:读取本地JSON文件,并显示到LsitView上,下面详细介绍:1 [2 {3 "operator":"admin1",4 "loginDate":"2012-10-20 10:28:10",5 "logoutDate":"2012-10-20 10:32:10"6 },7 {8 "operator":"admin2",9 "l...程序功能:读取本地JSON文件,并显示到LsitView上,下面详细介绍:
1 [2 {3 "operator":"admin1",4 "loginDate":"2012-10-20 10:28:10",5 "logoutDate":"2012-10-20 10:32:10"
6 },7 {8 "operator":"admin2",9 "loginDate":"2012-10-22 10:20:10",10 "logoutDate":"2012-10-22 10:32:10"
11 },12 {13 "operator":"admin3",14 "loginDate":"2012-10-23 10:28:10",15 "logoutDate":"2012-10-23 10:32:10"
16 },17 {18 "operator":"admin4",19 "loginDate":"2012-10-20 10:28:10",20 "logoutDate":"2012-10-20 10:32:10"
21 }22 ]
先准备内容如上的"json.txt"文件,放到项目的assets目录下(此处可以是本地SD卡只是读取的方式有些异同)。首先要读出json.txt的内容,要访问assets下的资源,需要使用AssetManager类的open(filename)方法,文中省去(AssetManager assetManager = getAssets();)步骤,简写为Context.getAssets().open(filename)。open方法返回一个输入流,我们便可以通过这个流来得到json字符串。
1 /**
2 * 读取本地文件中JSON字符串3 *4 *@paramfileName5 *@return
6 */
7 privateString getJson(String fileName) {8
9 StringBuilder stringBuilder = newStringBuilder();10 try{11 BufferedReader bf = new BufferedReader(newInputStreamReader(12 getAssets().open(fileName)));13 String line;14 while ((line = bf.readLine()) != null) {15 stringBuilder.append(line);16 }17 } catch(IOException e) {18 e.printStackTrace();19 }20 returnstringBuilder.toString();21 }
获得JSON字符串,我们便可以解析,进而得到对我们有用的数据,Adnroid已经加入了org.json.*,所以我对json的操作也变得简单起来,使用JSONArray array = new JSONArray(str) 就能把我们刚刚得到的JSON串传化为JSONArray,请注意观察我们的josn.txt的内容,其中包括了四组数据结构相同的数据,每一组数据看成一个JSONObject(包含了若干键值对,很像Map),而这些JSONObject便组成了一组JSONArray数组,所以我们只要遍历这个array就可以得到其中的所有JSONObject了,有了JSONObject就可以通过Key获得对应的Value值了。
1 /**
2 * 将JSON字符串转化为Adapter数据3 *4 *@paramstr5 */
6 private voidsetData(String str) {7 try{8 JSONArray array = newJSONArray(str);9 int len =array.length();10 Mapmap;11 for (int i = 0; i < len; i++) {12 JSONObject object =array.getJSONObject(i);13 map = new HashMap();14 map.put("operator", object.getString("operator"));15 map.put("loginDate", object.getString("loginDate"));16 map.put("logoutDate", object.getString("logoutDate"));17 data.add(map);18 }19 } catch(JSONException e) {20 e.printStackTrace();21 }22 }
填充完我们的数据集合,就可以放置到Adapter中,并显示到LsitView中,下面给出完整代码,
json.xml
1 <?xml version="1.0" encoding="utf-8"?>
2
3 android:layout_width="fill_parent"
4 android:layout_height="fill_parent"
5 android:orientation="vertical" >
6
7
9 android:layout_width="fill_parent"
10 android:layout_height="wrap_content" >
11
12
13
json_item.xml
1 <?xml version="1.0" encoding="utf-8"?>
2
3 android:layout_width="fill_parent"
4 android:layout_height="fill_parent" >
5
6
8 android:layout_width="fill_parent"
9 android:layout_height="wrap_content"
10 android:layout_marginLeft="15dp" />
11
12
14 android:layout_width="wrap_content"
15 android:layout_height="wrap_content"
16 android:layout_alignLeft="@id/operator_tv"
17 android:layout_below="@id/operator_tv" />
18
19
21 android:layout_width="wrap_content"
22 android:layout_height="wrap_content"
23 android:layout_alignTop="@+id/loginDate_tv"
24 android:layout_marginLeft="15dp"
25 android:layout_toRightOf="@+id/loginDate_tv" />
26
27
java代码
1 public class JSONTextActivity extendsActivity {2
3 privateListView listView;4 private List>data;5 private final static String fileName = "json.txt";6 privateProgressDialog pd;7
8 @Override9 protected voidonCreate(Bundle savedInstanceState) {10 super.onCreate(savedInstanceState);11 setContentView(R.layout.json);12 init();13 pd.show();14 newDataThread().start();15
16 }17
18 /**
19 * 初始化20 */
21 private voidinit() {22 listView =(ListView) findViewById(R.id.listView);23 data = new ArrayList>();24 pd = new ProgressDialog(this);25 pd.setMessage("数据加载中……");26
27 }28
29 /**
30 * 加载数据线程31 */
32 class DataThread extendsThread {33
34 @Override35 public voidrun() {36 String jsonStr =getJson(fileName);37 setData(jsonStr);38 dataHandler.sendMessage(dataHandler.obtainMessage());39 }40
41 }42
43 /**
44 * 加载数据线程完成处理Handler45 */
46 Handler dataHandler = newHandler() {47
48 public voidhandleMessage(android.os.Message msg) {49 if (pd != null) {50 pd.dismiss();51 }52 SimpleAdapter adapter = newSimpleAdapter(getApplicationContext(),53 data, R.layout.json_item, new String[] { "operator",54 "loginDate", "logoutDate" }, new int[] {55 R.id.operator_tv, R.id.loginDate_tv,56 R.id.logoutDate_tv });57 listView.setAdapter(adapter);58 }59 };60
61 /**
62 * 读取本地文件中JSON字符串63 *64 *@paramfileName65 *@return
66 */
67 privateString getJson(String fileName) {68
69 StringBuilder stringBuilder = newStringBuilder();70 try{71 BufferedReader bf = new BufferedReader(newInputStreamReader(72 getAssets().open(fileName)));73 String line;74 while ((line = bf.readLine()) != null) {75 stringBuilder.append(line);76 }77 } catch(IOException e) {78 e.printStackTrace();79 }80 returnstringBuilder.toString();81 }82
83 /**
84 * 将JSON字符串转化为Adapter数据85 *86 *@paramstr87 */
88 private voidsetData(String str) {89 try{90 JSONArray array = newJSONArray(str);91 int len =array.length();92 Mapmap;93 for (int i = 0; i < len; i++) {94 JSONObject object =array.getJSONObject(i);95 map = new HashMap();96 map.put("operator", object.getString("operator"));97 map.put("loginDate", object.getString("loginDate"));98 map.put("logoutDate", object.getString("logoutDate"));99 data.add(map);100 }101 } catch(JSONException e) {102 e.printStackTrace();103 }104 }105 }
运行效果如下:
-
关于uni-app实现读取本地系统配置文件
2021-03-30 16:26:17//*** requestFileSystem: 请求本地文件系统对象 plus.io.requestFileSystem( type, succesCB, errorCB ); //获取指定的文件系统,可通过type指定获取文件系统的类型。 参数: type: ( Number ) 必选 本地文件... -
uni-app 图片(文件) 本地存储解决方案
2020-12-19 13:48:06文件或图片每一次都从远端下载,导致离线状态页面空白,或者耗费带宽和时间太多导致的用户体验差,因此,我们需要一种方案去解决这样的问题已经下载的文件或图片等资源,直接从从设备本地获取而不是从远端下载解决... -
uni-read-pages:读取`pages.json`文件以生成路由表
2021-05-12 21:09:36通过 配合此库,可以随心所欲的读取 pages.json 下的所有配置 安装 您可以使用 Yarn 或 npm 安装该软件包(选择一个): Yarn yarn add uni-read-pages npm npm install uni-read-pages 开始 配置 vue.config.js ... -
uniAPP文件接收
2019-09-26 19:25:07uniAPP文件接收根据MultipartHttpServletRequest获取LinkedHashMap进行便利获取 -
uni-app 上传文件(三)
2020-12-29 04:03:06uni.uploadFile(OBJECT)将本地资源上传到...如页面通过uni.chooseImage等接口获取到一个本地资源的临时文件路径后,可通过此接口将本地资源上传到指定服务器。OBJECT 参数说明参数名 类型 必填 说明 平台支持url ... -
uni app中本地存储与获取
2022-04-21 21:45:47以服务器返回的token为例: 存储token: uni.setStorage({ key: 'token', ...获取token: 方式一: let token = '' if(uni.getStorageSync('token')){ // 变量token可以直接使用 前面无需加this ... -
uni-app 接口 - 从本地相册选择图片或使用相机拍照
2020-12-19 13:48:10uni.chooseImage(OBJECT) 从本地相册选择图片或使用相机拍照。count Number 否 最多可以选择的图片张数,默认9sizeType StringArray 否 original 原图,compressed 压缩图,默认二者都有sourceType StringArray 否 ... -
APP读取本地文件夹内视频播放
2020-12-19 13:48:04uni.getStorageSync(KEY)// 下载文件资源到本地,客户端直接发起一个 HTTP GET 请求,返回文件的本地临时路径。uni.downloadFile(OBJECT)// 保存视频到本地uni.saveFile(OBJECT)// 将 data 存储在本地缓存中指定的 ... -
利用ExcelJS读取Excel文件
2021-01-07 06:53:54/* npm install exceljs */ const Excel = require('exceljs') const fs=require('fs'); const excelfile=ceshi.xlsx; var workbook = new Excel.Workbook... //获取第一个 worksheet.eachRow(function(row, rowNumb -
UNI-APP_获取文件信息,获取图片文件大小
2022-01-06 16:35:43https://uniapp.dcloud.io/api/file/file?id=getfileinfo uni.getFileInfo({ filePath:'文件路径', success:imgInfo=>{ console.log(imgInfo.size); } }) -
uni-app,安卓本地文件选择,返回路径
2020-09-17 12:04:47安卓选择本地文件时,需要返回文件路径,然后调用uni-app的上传接口去上传文件。首先是要选择文件,并返回文件路径 // chooseFile.js文件内容 function chooseFile(callback, acceptType) { //acceptType为你要查的... -
uniapp上传本地文件
2021-08-16 09:20:43uniapp如何将本地文件附件提交接口上传到服务器 使用 plus.io.resolveLocalFileSystemURL: 通过URL参数获取目录对象或文件对象 使用 plus.io.FileReader: 文件系统中的读取文件对象,用于获取文件的内容 使用 ... -
uni-app文件下载,获取已下载列表以及文件预览Android和IOS的处理(非视频图片。)
2022-03-02 10:15:06uni-app文件下载,获取已下载列表以及文件预览.Android和IOS的处理 -
在 uni-app 中使用 webview 打开本地文件,打开不成功
2021-08-09 11:14:50在 uni-app 中使用 webview 打开本地文件,打开不成功出现套娃现象的解决方案 小程序仅支持加载网络网页,不支持本地html 排查本地文件是否按照官方给出的路径建立的。 uni-app 项目根目录->hybrid->html ... -
UNI-APP本地图片转Base64
2021-05-27 17:15:09UNI-APP本地图片转Base64方法一:方法二: 开发过程中遇到需要将本地图片编码成base64的场景,怕忘记了,所以留个记录。 方法一: uni.chooseImage({ success: (chooseImageRes) => { const tempFilePaths =... -
uni-app文件操作
2020-12-17 13:12:28创建、获取文件 async getFileEntry(fileName, dirEntry) { return new Promise((resolve) => { plus.io.requestFileSystem(plus.io.PRIVATE_DOC, function(fs) { let entry = dirEntry || fs.root... -
uni-app 打开文件(文件或文件流)
2022-02-17 10:19:57需求:uniapp可以在平板上面打开excel文件或word文件,可以用wps打开后打印 1. 创建个koa项目模拟后台返回二进制文件流 const router = require("koa-router")(); const xlsx = require("node-xlsx"); router.... -
uni-app 前后端实战课 -悦读.txt
2020-05-07 15:32:38第13讲 : 我的界面布局、用户发布文章获取 第14讲 : 删除文章功能实现 第15讲 : 完成文章编辑功能 第16讲 : 首页文章列表布局、下拉刷新、上拉加载、分类切换 第17讲 : 详情页面布局、骨架屏数据加载 第18讲 : ... -
uni-app实现文件管理器(Android)
2021-01-07 10:19:062. 添加文件页(/pages/directory/directory) - 点击文件列表页右上角 +, 进入该页面,扫描本地根目录所有文件 3. 选择文件功能(/pages/directory/directory) - 用户可以选择多个文件,点击确定,确认添加文件,... -
uni-app导入本地json数据,使用js文件存储
2020-07-20 13:21:50uni-app导入本地json数据 在uniapp项目的时候,想把数据存到一个文件里 在网上找的时候发现大家都转载的一样的代码,于是就写上我的 json导入本地数据 json.js里面 let data =[ { id:"14654651162162", title:... -
uni-app IOS的threeJS本地obj、mtl文件的读取
2020-06-09 12:04:00uni-app IOS的threeJS本地obj、mtl文件的读取 最近有个项目获取的是基于3D模型的obj文件与材质mtl文件的获取进行渲染控制,使用的混合开发框架是uniapp,其中遇到的问题是IOS端的obj、mtl文件的获取有问题,不知道... -
UniApp实战:动态数据(请求封装、获取定位等)
2020-12-19 13:48:061、Uni-App API调用(网络请求、获取位置等)2、获取高德开放平台API - 天气查询3、Uni-App 引用npm第三方库4、Uni-App + Vuex 数据持久化下面我们来具体看看Uni-App API调用(网络请求、获取位置等)一、uni.request... -
UNI-Excel插件
2018-11-13 12:19:35使用UNI-Excel،,您可以创建、编辑和读取Excel文件. 换句话说,您可以将用户评分保存在Excel文件中,并在将来阅读这些信息。 在这个问题上有很多种方法,但每一种方法都有失败的地方。 有些方法无法创建Excel文件,... -
读取csv文件url内容 并转html表格显示
2020-07-15 16:23:23读取csv文件url内容 并转html表格显示