标签:close stringbu 读写 edr 换行符 except utf-8 rac +=
读取文件 String?Content?=?"";?//?文件很长的话建议使用StringBuffer try?{ FileInputStream fs=new FileInputStream("文件录取"); InputStreamReader?isr?=?new?InputStreamReader(fis,?"UTF-8"); BufferedReader?br?=?new?BufferedReader(isr); String?line?=?null; while?((line?=?br.readLine())?!=?null)?{ Content?+=?line; Content?+=?"\r\n";?//?补上换行符 }catch?(Exception?e)?{????????? e.printStackTrace(); } 写入文件 StringBuffer sb=new StringBuffer();//文件内容 try?{ FileOutputStream fos=new FileOutputStream("文件路径"); OutputStreamWriter osw=newOutputStreamWriter(fos,"utf-8"); osw.write(sb); osw.close(); }catch?(Exception?e)?{????????? e.printStackTrace(); }
标签:close stringbu 读写 edr 换行符 except utf-8 rac +=
原文地址:https://www.cnblogs.com/weibanggang/p/9347778.html