Android下新建文件的问题

来源:互联网 发布:博弈大师交易软件 编辑:程序博客网 时间:2024/06/06 14:05
Android下碰到一个比较诡异的问题: 通过一下两种方式居然得到不同的效果: 

第一种: String userIconPath = FileManager.getUserHeadPath(config.getSchoolId(),config.getUserTel()+"/"+config.getUserId()+"userIcon.png");
if(new File(userIconPath).exists())
{
Log.e("头像未被设置",userIconPath);
headIcon.setImageBitmap(FileManager.getBitmap(context));
}
第一种的效果是:新建了一个名为“3userIcon.png”的文件夹.

第二种:String userIconPath = FileManager.getUserHeadPath(config.getSchoolId(), config.getUserTel());
String iconPath = userIconPath+"/"+config.getUserId()+"userIcon.png";
//服务端请求头像的数据,本地存在从本地取,否则,从服务器下载下来再再本地取
if(new File(iconPath).exists())
{
Log.e("头像未被设置",userIconPath);
headIcon.setImageBitmap(FileManager.getBitmap(context));
}
第二种的效果是并不新建“3userIcon.png”,只有在new File(iconPath).createNewFile();才新建“3userIcon.png”的图片,注意:是图片

可能和FileManager.getUserHeadPath这个方法有关,但是我找不到原因

public static final String getUserHeadPath(int schoolId, String account) {
        if (hasSdcard()) {
            File path = new File(FileManager.USER_HEAD_BASE + "/" + schoolId
                    + "_" + account);
            if (!path.exists()) {
                path.mkdirs();
            }
            return FileManager.USER_HEAD_BASE + "/" + schoolId + "_" + account;
        }
        return null;
    }

是不是我可以理解成,假如把FileManager.getUserHeadPath和“/3userIcon.png”放到一起然后封装到File里以后,因为前者可以创建文件夹,封装以后3userIcon.png也自然被创建成文件夹了,但是我并没有mkdirs()啊?这是什么原因呢?
0 0
原创粉丝点击