相关疑难解决方法(0)

从资产中读取文件

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()方法时无法识别.这里有解决方案吗?

android

167
推荐指数
8
解决办法
31万
查看次数

如何在python 2.4中安全地打开/关闭文件

我目前正在编写一个小脚本,可以在我们的一个服务器上使用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时,安全处理文件对象的最佳做法是什么?

python file-io python-2.4

81
推荐指数
3
解决办法
13万
查看次数

标签 统计

android ×1

file-io ×1

python ×1

python-2.4 ×1