Phonegap:如何导航设备文件目录

时间:2014-04-24 14:01:07

标签: cordova phonegap-plugins

我只是在寻找类似于<input type="file" />功能的行为,但我没有运气。

我已经尝试了fileSysteminAppBrowser,但看起来这种行为并不在这些API中。

任何帮助?

更新:这是我用于在文件目录中搜索的代码

var onDeviceReady = (function () {
    alert('device ready');
    var button = document.getElementById('loadbutton');
    button.addEventListener('touchstart', function () {
         window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onSuccess, fail);

         function onSuccess(fileSystem) {
             alert(fileSystem.name);
             alert(fileSystem.root.name);
         }

         function fail(error){
             alert('File System Error: ' + error.code);
         }

    }, false);
}());

1 个答案:

答案 0 :(得分:0)

var onDeviceReady = (function () {
    alert('device ready');
    var button = document.getElementById('loadbutton');
    button.addEventListener('touchstart', function () {
         window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onSuccess, fail);
 function onSuccess(fileSystem) {
             fileSystem.root.getDirectory("DO_NOT_DELETE", {
                create: true,
                exclusive: false
            }, gotDirEntry, fail);
         }

         function fail(error){
             alert('File System Error: ' + error.code);
         }
        function gotDirEntry(dirEntry) {
            dirEntry.getFile("sample.json", {create: true, exclusive: false},gotfile, fail);
        }
function gotfile(fileentry){
console.log("file ");
}

    }, false);
}());