0

I want to read the file content of cordova asset index.html file using Java. This is the code I am currently using.

        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 get the following error message: I/O error: java.nio.file.NoSuchFileException: file:/android_asset/www/index.html

I have also tried setting file path to "index.html" and "www/index.html" which also shows the same error. I just don't know which path I have to use here.

Daniel Resch
  • 584
  • 3
  • 12

1 Answers1

1

When the app is compiled, the structure goes as follow in app/src/main

  assets/www
  java
  libs
  res

So I guess you're trying to target ./../assets/www/index.html relative to the java folder....

Eric
  • 9,870
  • 14
  • 66
  • 102
  • thank you very much for your answer, and your efforts :) I am quite sure the problem was that this was in fact a cordova android application and as soon as I compiled it, the entire file system was android based. However I was able to solve my problem in a different way - will post that. thx though – Daniel Resch Apr 05 '23 at 23:59