package com.weaver.seconddev.chapanda.test;

import java.io.*;
import java.util.UUID;

public class test7 {
    public static void main(String[] args) {
        String uuid = UUID.randomUUID().toString();
        System.out.println("uid:"+uuid);

        String filePath = "/Users/apple/Downloads/20250715/浙文考勤模块开发需求.docx"; // 文件路径
        try {
            InputStream inputStream = new FileInputStream(new File(filePath));

            byte[] data = convertInputStreamToBytes(inputStream);
            System.out.println("data:"+data.length);
// 使用 inputStream 进行文件操作
            System.out.println("文件已成功转换为 InputStream");
            inputStream.close();
        } catch (FileNotFoundException e) {
            System.err.println("文件未找到: " + e.getMessage());
        } catch (IOException e) {
            System.err.println("IO 异常: " + e.getMessage());
        }

    }


    public static  byte[] convertInputStreamToBytes(InputStream inputStream) throws IOException {
        ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
        System.out.println("inputStream2:{}"+inputStream.available());
        byte[] buffer = new byte[4096];
        int bytesRead;
        while ((bytesRead = inputStream.read(buffer)) != -1) {
            byteStream.write(buffer, 0, bytesRead);
        }
        System.out.println("byteStream:{}"+byteStream.toByteArray().length);
        return byteStream.toByteArray();
    }
}
