public class Utils {
public static List<Message> getMessages() {
//File file = new File("file:///android_asset/helloworld.txt");
AssetManager assetManager = getAssets();
InputStream ims = assetManager.open("helloworld.txt");
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用此代码尝试从资产中读取文件.我尝试了两种方法来做到这一点.首先,当File我收到使用FileNotFoundException时,使用AssetManager getAssets()方法时无法识别.这里有解决方案吗?
我目前正在编写一个小脚本,可以在我们的一个服务器上使用Python.服务器只安装了Python 2.4.4.
直到2.5出来之后我才开始使用Python,所以我习惯了以下形式:
with open('file.txt', 'r') as f:
# do stuff with f
Run Code Online (Sandbox Code Playgroud)
但是,with2.5之前没有声明,我无法找到有关手动清理文件对象的正确方法的示例.
使用旧版本的python时,安全处理文件对象的最佳做法是什么?