更新
只需<preference name="AndroidPersistentFileLocation" value="Compatibility" />
从 config.xml 中删除,或更改"Compatibility"
for "Internal"
,似乎负责将 null 值添加到数组响应中,如下所述
我正在使用带有 Ionic2 的 cordova 文件插件,如果不是你的情况,也许这可以给你一些亮点。
我对这个错误的跟踪将我带到.../plugins/cordova-plugin-file/www/fileSystems-roots.js
fsName -> FileSystem 的地图。
这让我认为这是一个错误,但我什至不知道如何报告它。
无论如何,问题在于对 map 的响应包含一个空对象,正如您在下面的响应副本中看到的那样:
[
null
, {"fullPath":"/","filesystemName":"persistent","isDirectory":true,"nativeURL":"file:...","filesystem":1,"isFile":false,"name":""}
, {"fullPath":"/","filesystemName":"content","isDirectory":true,"nativeURL":"content:...","filesystem":1,"isFile":false,"name":""}
, {"fullPath":"/","filesystemName":"assets","isDirectory":true,"nativeURL":"file:...","filesystem":1,"isFile":false,"name":""}
, {"fullPath":"/","filesystemName":"cache","isDirectory":true,"nativeURL":"file:...","filesystem":1,"isFile":false,"name":""}
]
同样,我使用的是 ionic2,如果你也是这种情况,你可以直接使用 File 插件,按照以下步骤操作:
0-安装插件(如果您收到此错误,我想您已经完成了此步骤)
1-将插件作为提供者导入模块中,例如
import { File } from '@ionic-native/file';
@NgModule({
...
, providers: [
...
, File
...
]
...
})
2-在您的组件中添加插件作为提供者
import { File } from '@ionic-native/file';
export class FileCreatorComponent {
constructor(..., private file: File, ...) { }
3-根据此页面Ionic2 Native file plugin使用它,例如创建(如果存在则覆盖)你可以这样做:
createFile() {
var filePath= this.file.externalRootDirectory + 'Download/';
//var filePath= 'file:///storage/emulated/0/Download/'; If the first doesn't work you can put this path, NOT RECOMMENDED, because the first should work
var fileName= 'newOne.txt';
this.file.writeFile(filePath, fileName, 'Lorem ipsum', { replace: true } )
.then(() => {
console.log('File created');
});
}