我遇到Ext.device.filesystem.FileEntry.read()方法的问题。当我尝试将text / JSON文件作为文本读取时,我得到一个空白文件。任何的想法?看起来像extjs文件阅读器的readastext方法是错误的。
以下不起作用:
var fileEntry = new Ext.device.filesystem.FileEntry(newFilePath, fileSystem);
fileEntry.read({
//type: "binaryString",
encoding: 'UTF8',
type: "text",
//type: "text",
success: function(fileData) {
console.log('--- fileData');
console.log(fileData);
console.log('//--- fileData');
self.onUploadJSONSuccess(fileData, fileName, networkId, activityId, section, showWaitScreen, callback);
},
failure: function(error) {
if(showWaitScreen) {
console.log('Failed to read file: ' + error);
Ext.Msg.alert('Failed to read file: ' + error);
}
}
});
但是如果我将类型从“text”更改为“binaryString”,它会读取文件,但当然会弄乱特殊字符。
var fileEntry = new Ext.device.filesystem.FileEntry(newFilePath, fileSystem);
fileEntry.read({
type: "binaryString",
success: function(fileData) {
console.log('--- fileData');
console.log(fileData);
console.log('//--- fileData');
self.onUploadJSONSuccess(fileData, fileName, networkId, activityId, section, showWaitScreen, callback);
},
failure: function(error) {
if(showWaitScreen) {
console.log('Failed to read file: ' + error);
Ext.Msg.alert('Failed to read file: ' + error);
}
}
});
此致 瓦希德
答案 0 :(得分:0)
将编码更改为“UTF-8”就可以了。因此,工作代码如下:
fileEntry.read({
//type: "binaryString",
type: "text",
encoding: "UTF-8",
success: function(fileData) {
console.log('--- fileData');
console.log(fileData);
console.log('//--- fileData');
self.onUploadJSONSuccess(fileData, fileName, networkId, activityId, section, showWaitScreen, callback);
},
failure: function(error) {
if(showWaitScreen) {
console.log('Failed to read file: ' + error);
Ext.Msg.alert('Failed to read file: ' + error);
}
}
});