账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    Word2Vec中new LineSentenceIterator()默认File类型,multipartfile咋整?
    33
    0

    看到的好多资料是,在加载语料库的时候是直接给定某个路径下的文件,比如:

    SentenceIterator iter = new LineSentenceIterator(new File("/Users/cvn/Desktop/file.txt"));

    但是,我现在需要在springboot下用multipartfile来传入,不想把路径直接写死,想让用户随便选择分好词的文件,部分代码如下:

    public train(MultipartFile source_file, MultipartFile des_file,Integer m1,Integer m2,Integer m3,Integer m4,Integer m5) throws IOException {
            
            SentenceIterator iter = new LineSentenceIterator(new File(source_file.getOriginalFilename()));

    getOriginalFilename()---该方法有个提示是:This may contain path information depending on the browser used,but it typically will not with any other than Opera.

    所以,在测试的时候IE浏览器显示了盘符,运行正常,但是谷歌浏览器加载文件只是显示了文件名,就一直报错:"Please specify an existing file"

    看了下源代码,这是没有找到还是没转换成file的意思??
    public LineSentenceIterator(File f) {
            if (!f.exists() || !f.isFile())
                throw new IllegalArgumentException("Please specify an existing file");
            try {
                this.f = f;
                this.file = new BufferedInputStream(new FileInputStream(f));
                iter = IOUtils.lineIterator(this.file, "UTF-8");
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

    现在不知道要怎么改,才能解决谷歌浏览器不报错,请大家帮帮忙!!( T﹏T )

    1
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 10 元积分
        全部回答
    • 0
    • 李小不 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部