黑马程序员技术交流社区
标题:
io字节流的案例拓展练习~~有错误请给我指出,感激不尽
[打印本页]
作者:
潘俊
时间:
2015-11-15 23:54
标题:
io字节流的案例拓展练习~~有错误请给我指出,感激不尽
这是一个io字节流,向文本txt写入数据,导师说这样可能出现编码错误.但是这是在没学字符流的前写的案例,请不要在意这些细节~~~~带有时间提示会把当时录入数据的时间录入到txt文本里,其实还有很多bug,和大家一起找bug吧
<p>public static void main(String[] args) throws IOException {</p><p>//创建输出流
FileOutputStream fot = new FileOutputStream("wangxin.txt",true);
writeText(fot);
}
public static void writeText (FileOutputStream fot) throws IOException {
System.out.println("请输入要写入的内容");
Scanner sc =new Scanner(System.in);
while (true) {
long s = System.currentTimeMillis();
Date d = new Date();</p><p>//创建日期时间的显示模板
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
String s2 = sdf.format(d); //将时间转换成自定义格式的显示类型
String s1 = sc.nextLine();</p><p>//退出输入"quit"的时候
if ("quit".equals(s1)) {
break;
}</p><p>//清除文本记事本里面的内容
if ("clean".equals(s1)) {
fot = new FileOutputStream("wangxin.txt");
} else {</p><p>//若没有以上操作,直接写入文本
fot.write(s1.getBytes());
fot.write("\t\t\n".getBytes());
fot.write("\t\t\t\t\t\t\t\t\t\t".getBytes());
fot.write(s2.getBytes());
fot.write("\n".getBytes());
//System.out.println(s2);
}
}</p><p> //关闭流
fot.close();
}
</p><p> </p>
复制代码
还是个技术小白,就是拿着上课做的拓展案例,导师让做完之后,觉得自己能够实现什么的功能,欢迎回复/\
作者:
潘俊
时间:
2015-11-16 00:14
怎么都没有人回复啊
作者:
醉叶惜秋
时间:
2015-11-16 00:27
进来学习来的
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2