首页 > 解决方案 > 存储个人资料图片的图像文件的问题

问题描述

我正在为大学做一个课程项目,我负责让配置文件系统正常运行。我们的讲师给了我们一些示例代码来让文件上传工作,我将使用它来制作用户的个人资料图片,但是即使我的代码看起来非常相似,我似乎无法让它工作。问题是该文件实际上不会在我的项目中创建和保存,但我的讲师给我的代码却可以!

这是讲师给我的代码:

        NewsStory newsstory = new NewsStory();
        newsstory.uniqueid = "story_"+System.currentTimeMillis();
        newsstory.dateItWasPublished = System.currentTimeMillis();
        newsstory.title = toProcess.params.get("title");
        newsstory.description = toProcess.params.get("description");
        newsstory.journalists.add(toProcess.params.get("journalist"));
        newsstory.filepathToImage = toProcess.params.get("fileupload");

        File uploaded = new File(newsstory.filepathToImage);
        int ind = newsstory.filepathToImage.lastIndexOf('.');
        String extension = newsstory.filepathToImage.substring(ind);
        uploaded.renameTo(new File("httpdocs/"+newsstory.uniqueid+extension));
        newsstory.filepathToImage = newsstory.uniqueid+extension;
        //At this point you would normally add the newsstory to the database
        MVMap<String, NewsStory> newsStories = db.s.openMap("NewsStories");
        newsStories.put(newsstory.uniqueid, newsstory);

这基本上从通过表单传入的文件上传参数中获取一个字符串并运行下面的代码。这是我的代码:

                    user.userEmail = toProcess.params.get("email");
                    user.profilePicturePath = toProcess.params.get("filepath");

                    System.out.println(user.profilePicturePath);

                    File uploaded = new File(user.profilePicturePath);
                    int ind = user.profilePicturePath.lastIndexOf('.');
                    String extension = user.profilePicturePath.substring(ind);
                    uploaded.renameTo(new File("httpdocs/"+user.username+"ProfilePicture"+extension));
                    user.profilePicturePath = user.username+"ProfilePicture"+extension;
                    System.out.println(user.profilePicturePath);

                    users.put(user.username, user);
                    db.commit();

有谁知道为什么我可能会遇到这个问题?

标签: javafile

解决方案


推荐阅读