[英]how to node js write file not error name file?
我嘗試通過 nodejs 寫入文件: enter code here
fs.writeFileSync(fileName, file.data, "UTF-8"); 如果 fileName 是“abc”,它就起作用了。 但是如果 fileName = '훌쩍 커버렸어',它不能保存文件。 好像是 utf-8 error relative name 文件。 請幫我! 謝謝
此問題的一種解決方案是使用Buffer
class 將文件名編碼為字節緩沖區,然后再將其傳遞給fs.writeFileSync
function。例如:
const fs = require("fs");
const fileName = "훌쩍 커버렸어";
const encodedFileName = Buffer.from(fileName, "utf8");
fs.writeFileSync(encodedFileName, file.data, "UTF-8");
這將使用 UTF-8 字符集將文件名編碼為字節緩沖區,這樣您就可以成功保存文件。
最好的祝福!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.