JAVA IO 转换流
摘抄自 b站尚硅谷JAVA视频教程
InputStreamReader isr = null; OutputStreamWriter osw = null; try { FileInputStream fis = new FileInputStream("data.txt"); FileOutputStream fis2 = new FileOutputStream("data_gbk.txt"); isr = new InputStreamReader(fis,"utf-8"); osw = new OutputStreamWriter(fis2,"gbk"); char [] data = new char[20]; int len =-1; while ((len=isr.read(data))!=-1){ osw.write(data,0,len); System.out.print(new String(data,0,len)); } } catch (IOException e) { e.printStackTrace(); } finally { if(isr!=null) try { isr.close(); } catch (IOException e) { e.printStackTrace(); } if(osw!=null) try { osw.close(); } catch (IOException e) { e.printStackTrace(); } }