[英]How would I load an ogg file in node js
我的目標是在 node.js 中加載 ogg 文件我試過 ReadFile 但遇到了這個錯誤:無法讀取文件。 [錯誤:ENOENT:沒有那個文件或目錄,打開'Main\\game\\songs\\test\\Voices.ogg'] 並且該文件確實存在。
代碼:
fs.readdir('./game/songs', function(err, files){
if (err) {
console.log("Could not list the directory.", err)
return
}
files.forEach(function(file, index){
fs.readFile('./game/songs/'+file+"/Inst.ogg", function(err, data){
if (err) {
console.log("Could not read file.", err)
return
}
})
fs.readFile('./game/songs/'+file+"/Voices.ogg", function(err, data){
if (err) {
console.log("Could not read file.", err)
return
}
})
})
})
您應該傳遞文件的絕對路徑,使用內置path
模塊的join()
函數:
const path = require('path');
const fs = require('fs');
fs.readFile(path.join(__dirname, 'YOUR_PATH_HERE'), function(err, data) {});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.