我从 API 获取 var byteArr=[12,-123,43,99, ...] 之类的字节数组,然后我将其转换为 UTF-8 String
var utf8_str = String.fromCharCode.apply([], new Uint8Array(byteArr));
然后将 UTF-8 字符串转换为 Base64 字符串
var base64_str= window.btoa(utf8_str);
现在我正在Phonegap中的FileWriter将UTF-8或Base64字符串写入文件(xyz.pdf/xyz.jpg),但是打开它时它会显示空白文件。
function gotWriteFile(dirEntry) {
dirEntry.getFile(FILE_NAME, {create: true, exclusive: false}, gotFileWriteEntry, failWrite);
}
function gotFileWriteEntry(fileEntry) {
fileEntry.createWriter(gotFileWriter, failWrite);
}
function gotFileWriter(writer) {
writer.onwriteend = function(evt) {
console.log("File write successfully....");
hideModal();
};
writer.write(utf8_str);
//writer.write(base64_str);
}
什么是解决方案家伙....?