OutputStreamWriter bufferedWriter file 写文件 解决字符格式问题 UTF-8 GBK

时间:2023-01-17 22:24:37

OutputStreamWriter ow=new  OutputStreamWriter(new FileOutputStream(filePateh),"GBK");


bufferedWriter bw= new bufferedWriter (ow);

if(data !=null && !"".equals(date)){

 String [] str=data.split("\\|");

for (int i=0;i<str.length;i++){

   bw.write(str[i]);

   bw.newLine();//读取一行换行

}

}

//不能放在finally里关闭,会有影响数据不一致

bw.flush();

bw.close();

ow.close();