准备工作:需要使用coomos-net jar包。下载地址

Java上传图片到Ftp,包含上传后文件大小为0的问题和Properties配置文件的读取

一、 上传图片到FTP,文件大小为0的问题,解决:将ftp模式修改为Passive模式就可以了。

//将ftp模式修改为Passive模式
ftpClient.enterLocalPassiveMode();

二、配置文件的操作,具体介绍请看 Java中Properties类的用法总结

1.使用.properties配置文件的形式定义相关常量。

Java上传图片到Ftp,包含上传后文件大小为0的问题和Properties配置文件的读取

 2.在工具类中导入配置文件

private static Properties getFtpConfig(){
        Properties p=new Properties();
        String path=Thread.currentThread().getContextClassLoader().getResource("ftpConfig.properties").getPath();
        try {
          p.load(new FileInputStream(path));
//          System.out.println(p.getProperty("ftpUsername"));
//          System.out.println(p.getProperty("ftpPassword"));
//          System.out.println(p.getProperty("ftpServerIP"));
//          System.out.println(p.getProperty("basePath"));
          
        } catch (Exception e) {
          e.printStackTrace();
        } 
        return p;
      }
Properties

相关文章:

  • 2021-10-04
  • 2022-12-23
  • 2021-12-10
  • 2022-12-23
  • 2022-02-09
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-26
  • 2021-10-25
  • 2021-11-17
  • 2021-11-17
  • 2022-12-23
  • 2021-06-06
  • 2021-11-15
相关资源
相似解决方案