io流 java 添加bom头 文件前面添加内容
try {
FileInputStream fis = new FileInputStream("input.csv");
InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
BufferedReader br = new BufferedReader(isr);
FileOutputStream fos = new FileOutputStream("output.csv");
fos.write(new byte[]{(byte)0xEF, (byte)0xBB, (byte)0xBF});
OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");
BufferedWriter bw = new BufferedWriter(osw);
String line = null;
while((line = br.readLine()) != null) {
bw.write(line);
bw.newLine();
}
bw.close();
br.close();
} catch (IOException e) {
e.printStackTrace();
}
赞 (0)