這是跨平臺的創(chuàng)建文件夾,不像Android那樣還要通過 Environment.getExternalStorageDirectory() 的原生代碼來創(chuàng)建
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
// alert('ondeviceReady');
// window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
console.log("文檔中心===========>軟件準備就緒:設置檢測文件存儲目錄開始.");
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
console.log("文檔中心===========>檢測臨時文件存儲目錄方法");
//util.appRootDirName 全局變量,這里是zgky
fileSystem.root.getDirectory(filemanage_util.appRootDirName, {
create: true,
exclusive: false
}, function (entry) {
//網(wǎng)上流傳的資料中都是使用fullPath,在這里我獲取到的是相對目錄,在下載時使用會報錯,所以換做了toURL()
//這是一個全局全局變量,用以保存路徑
console.log("文檔中心===========>創(chuàng)建文件夾成功,正在設置相關的參數(shù)!");
filemanage_util.fullPath = entry.toURL();
// alert(util.fullPath);
console.log("文檔中心===========>創(chuàng)建文件夾成功:" + filemanage_util.fullPath);
//console.log(util.fullPath);
}, function () {
console.log("文檔中心===========>創(chuàng)建文件夾失??!");
});
console.log("文檔中心===========>檢測臨時文件目錄方法結束!");
}, function () {
console.log("文檔中心===========>創(chuàng)建文件夾失敗");
});
console.log("文檔中心===========>軟件準備就緒:設置檢測文件存儲目錄結束");
};
以上就是web創(chuàng)建本地文件夾的實現(xiàn)方法,如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!