JS API需要用什么样的路径访问resources/rawfile目录下的文件?
试了多种方法,例如"resources/rawfile/test.txt", "/resources/rawfile/test.txt", "entry/resources/rawfile/test.txt", "/entry/resources/rawfile/test.txt" 等全都不行,报错说no such file...
JS API需要用什么样的路径访问resources/rawfile目录下的文件?
试了多种方法,例如"resources/rawfile/test.txt", "/resources/rawfile/test.txt", "entry/resources/rawfile/test.txt", "/entry/resources/rawfile/test.txt" 等全都不行,报错说no such file...
JS API fileio系列API方法中,访问resources/rawfile目录下的文件需要使用相对路径。
相对路径是相对于当前JS文件的路径。假设你的JS文件名为index.js,resources/rawfile目录下有一个test.txt文件,那么你可以使用以下代码来读取该文件:
let content = fileio.readTextSync("resources/rawfile/test.txt");
在这里,路径"resources/rawfile/test.txt"是相对于index.js文件路径的相对路径。如果你的JS文件不在项目根目录下,那么你需要根据你的文件结构来确定相对路径的正确格式。