-1

I am working in android. For reading the file content, I am using the method

List<String> lines = Files.readAllLines(wiki_path);

But whem I am using this method I am getting this error:

The method readAllLines(Path) is undefined for the type MediaStore.Files.

Why can the compiler not find the method?

Path wiki_path = Paths.get("C:/tutorial/wiki", "wiki.txt");

try {
    List<String> lines = Files.readAllLines(wiki_path);
    for (String line : lines) {

        if(url.contains(line))
        {
            other.put(TAG_Title, name);
            other.put(TAG_URL, url);
            otherList.add(other);
            break;
        }
    }
}
ByteHamster
  • 4,884
  • 9
  • 38
  • 53
sheetal. gami
  • 47
  • 1
  • 10
  • Better you search 'how to read a file and store in list + android' may get the result. – Sree Apr 23 '15 at 06:06

1 Answers1

3

The method you're trying to use is a member of java.nio.file.Files - but that class (and indeed that package) doesn't exist on Android. Even if the Java 7 version existed, you're trying to use a method introduced in Java 8. The Files class you've imported is android.provider.MediaStore.Files which is an entirely different class.

Even if it compiled, the path you're providing looks ever so much like a Windows path, which wouldn't work on an Android device...

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • @sheetal.gami: Well I'd *start* by making sure you can find the file and open an `InputStream` on it. You can then wrap that in an `InputStreamReader`, then wrap that in a `BufferedReader` and read that line by line. There may well be something appropriate in `android.util`, but I can't see anything immediately - go with the slightly clunkier code and get that working first. – Jon Skeet Apr 23 '15 at 06:09