上传文件到本地服务器【工具类】


    /**
     * 上传文件
     * @param is
     * @return
     */
    public static String uploadFile(InputStream is,String name) throws Exception{
        String folder = name.substring(0, name.lastIndexOf("/"));

        File secondFolder = new File(folder);
        if(!secondFolder.exists()){
            secondFolder.mkdirs();
        }
        FileOutputStream fos = new FileOutputStream(name);
        byte[] buffer = new byte[1024*1024];
        int len = 0;
        while((len = is.read(buffer)) != -1)
        {
            fos.write(buffer,0,len);
        }
        fos.close();
        return name;
    }

你可能感兴趣的:(日常问题解决,java,开发语言)