文章目录
try {
String str1 = "asdfasdfaszdf,你,好,啊";
ByteArrayInputStream byteStrs = new ByteArrayInputStream(str1.getBytes(StandardCharsets.UTF_8));
byte[] bom = {(byte) 0xEF, (byte) 0xBB, (byte) 0xBF};
ByteArrayInputStream byteBom = new ByteArrayInputStream(bom);
Vector<InputStream> vector = new Vector<>();
vector.add(byteBom);
vector.add(byteStrs);
SequenceInputStream sis = new SequenceInputStream(vector.elements());
FileOutputStream finalFileOutputStream = new FileOutputStream("t1.csv");
byte[] bys = new byte[5];
int len;
while ((len = sis.read(bys)) != -1) {
finalFileOutputStream.write(bys, 0, len);
}
sis.close();
finalFileOutputStream.close();
} catch (IOException e) {
System.out.println(e.toString());
}