Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试获取应用程序数据文件的目录(/data/files)
我该怎么做?
我试过ContextWrapper.getFilesDir();但它说Non-static method 'getFilesDir()' cannot be referenced from a static context
ContextWrapper.getFilesDir();
Non-static method 'getFilesDir()' cannot be referenced from a static context
我使用它的上下文是:String[] filenames = ContextWrapper.getFilesDir(); 谢谢!
String[] filenames = ContextWrapper.getFilesDir();
编译器抱怨您需要context调用实例getFilesDir()。如果你在里面Activity,你可以这样做。-
context
getFilesDir()
Activity
File[] files = getFilesDir().listFiles();
, 因为Activity它本身就是一个Context. 相反,您需要传递context给要访问文件目录的类。
Context