---------------------- android培训、java培训、期待与您交流! --------------------------------------------
上次看输入输出的时候有一个细节没有注意,结果导致今天就发生了小小的悲剧。
就是一个简单的读入,输入输出问题 开始的时候
FileOutputStream fos=new FileOutputStream("D:\\asd.java");
PrintStream ps=new PrintStream(fos);
FileReade fr=new FileReader("D:\\asd.java");
byte[] bbuf = new byte[1024];
int hasRead = 0;
while ((hasRead =fr.read(bbuf)) > 0 )
{
ps.write(bbuf,0,hasRead);
}
结果
while ((hasRead =fr.read(bbuf)) > 0 )
这里就出问题了 因为fr里边就没有读取byte类型的方法,还好对字节流,字符流还有一点印象,马上重新看书,发现确实是这个问题忽略了,FileInputStream只能读取字节,而FileReader只能读取字符,把代码改了
FileOutputStream fos=new FileOutputStream("D:\\asd.java");
PrintStream ps=new PrintStream(fos);
FileInputStream fr=new FileInputStream("D:\\asd.java");
byte[] bbuf = new byte[1024];
int hasRead = 0;
while ((hasRead =fr.read(bbuf)) > 0 )
{
ps.write(bbuf,0,hasRead);
}
这样就好了 另外,JAVA还提供了InputStreamReader来将字节流转换成字符流,但是却没有将字符流转换为字节流的办法。
总结:以后学习的过程中一定要注意,不能忽略这些细小的东西,很可能就是自己觉得没什么用,没有去仔细掌握的东西就是以后的死穴。
android培训、java培训、期待与您交流! ----------------------详细请查看:http://edu.csdn.net/heima