Mr_xiao_cai
- 发布:2016-03-18 15:00
- 更新:2018-03-28 15:38
- 阅读:2536
Mr_xiao_cai (作者)
if (bluetoothSocket.isConnected()) {
console.log('开始接收数据');
var buffer = new ArrayBuffer(1024);
var InputStream = bluetoothSocket.getInputStream();
plus.android.importClass(InputStream);
var count = InputStream.read();
蓝牙的这段读数据流,,该怎么写
可使用原生实现一个文件读取返回String,然后通过native.js调用这个类,避免在js中使用byte[],代码如下:
原生代码:
package com.dcfs.teller.smartmobile.test;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class File {
public static String readFileSync(String path){
java.io.File file = new java.io.File(path);
System.out.println(file.canRead());
System.out.println(file.exists());
if(file.exists() && file.canRead()){
FileInputStream fi = null;
try {
fi = new FileInputStream(file);
int length = fi.available();
byte[] bytes = new byte[length];
fi.read(bytes);
String data = new String(bytes,"UTF-8");
return data;
} catch (FileNotFoundException e) {
return "";
} catch(IOException e2){
return "";
} catch(Exception e3){
return "";
}finally{
if(fi != null){
try {
fi.close();
} catch (IOException e) {
}
}
}
}else{
return "";
}
}
}
js代码:
var jsFile = plus.io.convertLocalFileSystemURL('_www/js/app.update.js');
var File = plus.android.importClass('com.dcfs.teller.smartmobile.test.File');
var data = File.readFileSync(jsFile);
1***@163.com
请问您怎么知道不支持的,没有办法了吗?
2020-02-11 17:17