想提问一下append(true)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | import java.io.BufferedOutputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; public class Buffered2 { public static void main(String[] args) { try { FileOutputStream b1= new FileOutputStream( "one.txt" ); BufferedOutputStream b2= new BufferedOutputStream( new FileOutputStream( "two.txt" )); long a=System.currentTimeMillis(); StringBuilder str= new StringBuilder(); for ( int i= 0 ;i< 100000 ;i++) { b1.write(i); str.append( true ); } long b=System.currentTimeMillis(); b1.close(); for ( int i= 0 ;i< 100000 ;i++) { b2.write(i); str.append( true ); } long c=System.currentTimeMillis(); b2.flush(); b2.close(); System.out.println( "one不使用缓冲流来写\n用时为:" +(b-a)); System.out.println( "two使用缓存流来写\n用时为:" +(c-b)+ "\n用缓冲流来写节省了" +((b-a)-(c-b))+ "ms" ); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } |
append(true)怎么使用呀 我感觉我这个瞎弄的起不到作用 另外为什么生成的txt是乱码 求解 谢谢啦~
0
收起
正在回答 回答被采纳积分+1
2回答
Java零基础入门18
- 参与学习 人
- 提交作业 7317 份
- 解答问题 14452 个
想要入门学编程?多年一直活跃在编程语言排行版前列的Java是一个很好的选择。本路径将从Java基础语法、面向对象、常用工具类三部分,为你开启软件开发的大门!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧