How to read a local text file?

前端 未结 20 2239
北恋
北恋 2020-11-21 05:28

I’m trying to write a simple text file reader by creating a function that takes in the file’s path and converts each line of text into a char array, but it’s not working.

20条回答
  •  隐瞒了意图╮
    2020-11-21 05:50

    Using Fetch and async function

    const logFileText = async file => {
        const response = await fetch(file)
        const text = await response.text()
        console.log(text)
    }
    
    logFileText('file.txt')
    

提交回复
热议问题