• java代码,io实现复制文件


    主要代码:

    try
            {
    //获取image文件夹的绝对路径
      String uploadfile = request.getSession().getServletContext().getRealPath("/image");
         //System.out.println("uploadfile="+uploadfile);
    //把“”替换成“/”,为什么是四个反斜杠,还在研究中
         String uploadpath=uploadfile.replaceAll("\\","/");
            String image_file=request.getSession().getServletContext().getRealPath("/slide_image");
            String slide_image_file=image_file.replaceAll("\\", "/");
           // System.out.println("slide_image_file="+slide_image_file);
            //复制后的图片 文件
            FileOutputStream fos = new FileOutputStream(slide_image_file+"/"+pic_name); //pic_name包含后缀名,如abc.jpg
             //需要复制的 图片文件
            FileInputStream fis = new FileInputStream(uploadfile+"/"+pic_name);
             byte[] buf = new byte[1024]; //缓存
             int len = 0;  //实际读取的文件流
             while((len=fis.read(buf))!=-1)
             {
              fos.write(buf,0,len);
             }
            fis.close();
            fos.close();
            }
            catch (IOException e)
            {
             throw new RuntimeException("复制文件失败");
            }
    你可以比现在做得更好
  • 相关阅读:
    js 实现继承的6种方式(逐渐优化)
    http2.0 特性
    http 206请求
    http put post请求区别
    stopPropagation 和stopImmediatePropagation区别
    JavaScript事件流
    BFC特性 形成BFC
    元素高度、宽度获取 style currentStyle getComputedStyle getBoundingClientRect
    三栏布局解决方案
    jquery vue 框架区别
  • 原文地址:https://www.cnblogs.com/hwm-php/p/3566317.html
Copyright © 2020-2023  润新知