我的目標是在 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
}
})
})
})
uj5u.com熱心網友回復:
您應該傳遞檔案的絕對路徑,使用內置path模塊的join()功能:
const path = require('path');
const fs = require('fs');
fs.readFile(path.join(__dirname, 'YOUR_PATH_HERE'), function(err, data) {});
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/317299.html
標籤:javascript html 节点.js
