public class copytextbybuf { public static void main(string[] args) { bufferedreader bufr = null; bufferedwriter bufw = null; try { bufr = new bufferedreader(new filereader("demo_src.txt")); bufw = new bufferedwriter(new filewriter("demo_desc.txt")); string line = null; //readline不带行终止符 while ((line = bufr.readline()) != null) { bufw.write(line); bufw.newline(); bufw.flush(); } } catch (ioexception e) { throw new runtimeexception("读写失败!"); } finally { try { if (bufr != null) bufr.close(); } catch (ioexception e) { throw new runtimeexception("读取关闭失败!"); } try { if (bufw != null) bufw.close(); } catch (ioexception e) { throw new runtimeexception("写入关闭失败!"); } } } }
newline()
无论读一行还是获取多个字符,其实最终都是在硬盘上一个一个读取。所以最终使用的还是read()一次读一个的方法。
如对本文有疑问, 点击进行留言回复!!
ScrollView和RecyclerView的滑动事件处理
配置JAVA环境+安装Android Studio全过程+踩坑记录
Android P Camera2当SD卡被拔出来自动切换到内部存储
android 多个edittext 判空监听 让Button动态是否可点击
Android开源项目滚轮选择器WheelPicker的基本用法总结
网友评论