原因写入的时候字符问题代码如下(注springmvc的错误原因和这里一样):

 

  public static void main(String[] args) throws IOException {
        String   fileName = "aaa.jar";
        System.out.println("start");
//        Files.copy(Paths.get(path,fileName),Paths.get("d://test//b.jar"));  //这种写法正常
        Path path = Paths.get(AppController.path, fileName);
        Path path1 = Paths.get("d://test//g.jar");

        File file = path.toFile();
        File file1 = path1.toFile();

        FileInputStream fileInputStream = new FileInputStream(file);
        OutputStream outputStream = new FileOutputStream(file1);
//        byte[] buff = new byte[fileInputStream.available()];  //原来的写法
// 下面是改正后的写法(绿色注释掉的错误写法)
        byte[] bts = new byte[1024*1024];
        int len=-1;
        while ((len=fileInputStream.read(bts)) != -1) {
            outputStream.write(bts, 0, len);
        }

//        outputStream.write(buff,0,buff.length);  //原来的写法
        outputStream.flush();
        outputStream.close();
        fileInputStream.close();
        System.out.println("over");
    }

 2、 SpringMVC的 ResponseEntity 下载的文件与原文件md5值不一样原因是在下载服务器的服务端设置了

headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); 导致的。解决办法:去掉该代码即可

相关文章:

  • 2021-08-23
  • 2022-12-23
  • 2021-08-20
  • 2021-12-02
  • 2021-06-07
  • 2021-06-26
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-26
  • 2022-01-18
  • 2022-01-18
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案