数据流实现ZIP文件的写入

public static void main(String[] args) {
         try (DataOutputStream out = new DataOutputStream(new FileOutputStream("D:\\aa\\c.zip"))) {
             String str = "好好的过精彩每一天,你是最棒的,拥有一颗肆意洒脱的心,加油zn123";
            byte[] b = str.getBytes();
            out.writeUTF(str);
            out.writeBytes("\r\n");
            for(int i =0; i < b.length; i++) {
                //字节类型会自动转为int类型
                out.writeByte(b[i]);
            }
            out.flush();
         
        } catch (IOException ex) {
            System.out.println(ex.getMessage());
        }
    }
   
}

你可能感兴趣的:(数据流实现ZIP文件的写入)