黑马程序员技术交流社区

标题: io字节流的案例拓展练习~~有错误请给我指出,感激不尽 [打印本页]

作者: 潘俊    时间: 2015-11-15 23:54
标题: io字节流的案例拓展练习~~有错误请给我指出,感激不尽
这是一个io字节流,向文本txt写入数据,导师说这样可能出现编码错误.但是这是在没学字符流的前写的案例,请不要在意这些细节~~~~带有时间提示会把当时录入数据的时间录入到txt文本里,其实还有很多bug,和大家一起找bug吧
  1. <p>public static void main(String[] args) throws IOException {</p><p>//创建输出流
  2.   FileOutputStream fot = new FileOutputStream("wangxin.txt",true);
  3.   writeText(fot);
  4. }
  5. public static void writeText (FileOutputStream fot) throws IOException {
  6.   System.out.println("请输入要写入的内容");
  7.   Scanner sc =new Scanner(System.in);
  8.   while (true) {
  9.    long s = System.currentTimeMillis();
  10.    Date d = new Date();</p><p>//创建日期时间的显示模板
  11.    SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
  12.    String s2 = sdf.format(d);  //将时间转换成自定义格式的显示类型
  13.    String s1 = sc.nextLine();</p><p>//退出输入"quit"的时候
  14.    if ("quit".equals(s1)) {
  15.     break;
  16.    }</p><p>//清除文本记事本里面的内容
  17.    if ("clean".equals(s1)) {
  18.     fot = new FileOutputStream("wangxin.txt");
  19.    } else {</p><p>//若没有以上操作,直接写入文本
  20.     fot.write(s1.getBytes());
  21.     fot.write("\t\t\n".getBytes());
  22.     fot.write("\t\t\t\t\t\t\t\t\t\t".getBytes());
  23.     fot.write(s2.getBytes());
  24.     fot.write("\n".getBytes());
  25.     //System.out.println(s2);
  26.    }
  27.   }</p><p>   //关闭流
  28.   fot.close();
  29. }
  30. </p><p> </p>
复制代码

还是个技术小白,就是拿着上课做的拓展案例,导师让做完之后,觉得自己能够实现什么的功能,欢迎回复/\

作者: 潘俊    时间: 2015-11-16 00:14
怎么都没有人回复啊
作者: 醉叶惜秋    时间: 2015-11-16 00:27
进来学习来的




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2