Java从cordova index.html读取文件内容



我想用Java读取cordova asset index.html文件的文件内容。这是我目前正在使用的代码。

Path filePath = Paths.get("file:///android_asset/www/index.html");
Charset charset = StandardCharsets.UTF_8;
try {
List<String> lines = Files.readAllLines(filePath, charset);
for(String line: lines) {
System.out.println(line);
}
} catch (IOException ex) {
System.out.format("I/O error: %s%n", ex);
}

我得到以下错误信息:I/O error: java.nio.file.NoSuchFileException: file:/android_asset/www/index.html

我也试过将文件路径设置为"index.html"one_answers"www/index.html"这也显示了同样的错误。我只是不知道该用哪条路径。

在编译应用程序时,app/src/main

中的结构如下所示
assets/www
java
libs
res

我猜你的目标是./../assets/www/index.html相对于java文件夹....