files.readAllLines 出错
Getting error on files.readAllLines
我在 android 工作。为了读取文件内容,我使用的是
方法
List<String> lines = Files.readAllLines(wiki_path);
但是当我使用这种方法时,我收到了这个错误:
The method readAllLines(Path) is undefined for the type MediaStore.Files.
为什么编译器找不到方法?
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;
}
}
}
与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
完全不同class。
即使编译成功,您提供的路径看起来也很像 Windows 路径,在 Android 设备上无法运行...
我在 android 工作。为了读取文件内容,我使用的是
方法List<String> lines = Files.readAllLines(wiki_path);
但是当我使用这种方法时,我收到了这个错误:
The method readAllLines(Path) is undefined for the type MediaStore.Files.
为什么编译器找不到方法?
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;
}
}
}
与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
完全不同class。
即使编译成功,您提供的路径看起来也很像 Windows 路径,在 Android 设备上无法运行...