• 文件读写操作inputStream转为byte[] , 将InputStream写入本地文件


     将InputStream写入本地文件

        /**
         * 将InputStream写入本地文件
         *
         * @param destination 写入本地目录
         * @param input       输入流
         * @throws IOException IOException
         */
        public static void writeToLocal(String destination, InputStream input)
                throws IOException {
            int index;
            byte[] bytes = new byte[1024];
            FileOutputStream downloadFile = new FileOutputStream(destination);
            while ((index = input.read(bytes)) != -1) {
                downloadFile.write(bytes, 0, index);
                downloadFile.flush();
            }
            input.close();
            downloadFile.close();
        }

    inputStream转为byte[]

        /**
         * inputStream转为byte[]
         *
         * @param inStream
         * @return byte[]
         * @throws IOException
         */
        public byte[] convert2ByteArray(InputStream inStream) throws IOException {
            ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
            byte[] buff = new byte[1024];
            int rc = 0;
            while ((rc = inStream.read(buff, 0, 1024)) > 0) {
                swapStream.write(buff, 0, rc);
            }
            byte[] in_b = swapStream.toByteArray();// in_b为转换之后的结果
            return in_b;
        }
  • 相关阅读:
    SpringSecurity Oauth2.0
    公钥与私钥
    Springboot集成SpringSecurity
    shiro2
    Maven的聚合工程(多模块工程)
    1.RabbitMQ
    3.使用Spring Data ElasticSearch操作ElasticSearch(5.6.8版本)
    2.ElasticSearch集群的搭建
    1.ElasticSearch相关概念
    Vuejs-网络
  • 原文地址:https://www.cnblogs.com/yadongliang/p/13226535.html
Copyright © 2020-2023  润新知