你好我正在做一个Windows 8 Javascript应用程序,你知道如何获取文件女巫的名字是来自C:\ Users \ Me \ Pictures \ thifolder的example2.dat我尝试使用Windows.Storage.StorageFile.getFileFromPathAsync("C:\Users\Me\Pictures\thisfolder");
但它没有用,因为我有另一个文件,如example1.dat,example3.dat example.jpg等。
希望我自己清楚,先谢谢
到目前为止,这是我的代码
function here() {
var getJsonStringAsync = function () {
return Windows.Storage.StorageFile.getFileFromPathAsync("C:\Users\Me\Pictures\thisfolder")
//Also tried this
//return Windows.Storage.KnownFolders.picturesLibrary.getFileAsync(u_u + "_" + u + "_" + ".dat")
.then(function (file) {
return Windows.Storage.FileIO.readTextAsync(file);
});
};
getJsonStringAsync().then(function (text) {
document.getElementById("line").innerHTML = text;
});
}
答案 0 :(得分:1)
读取图片库中文件的正确方法是: (不要忘记在你的应用程序的清单中声明对图片库的访问权)
var getJsonStringAsync = function () {
var picturesLibrary = Windows.Storage.KnownFolders.picturesLibrary;
return picturesLibrary.getFolderAsync("thisfolder").then(function (folder){
return folder.getFileAsync("example2.dat").then(function (file) {
return Windows.Storage.FileIO.readTextAsync(file);
});
});
};
答案 1 :(得分:0)
在JavaScript中,这里是如何播放音乐库中的“song.mp3”:
HTML:
<audio id="player1">Your browser does not support audio </audio>
JavaScript的:
var ml = Windows.Storage.KnownFolders.musicLibrary;
ml.getFileAsync("song.mp3").then(function (file) {
// its a storage file, so create URL from it
var s = window.URL.createObjectURL(file);
player1.setAttribute("src", s);
player1.play();
//});
});