java中的IO流 javaio流 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 flush刷新缓冲区,并且注意流使用完后及时关闭 字符流都是有缓冲的!在写入输出流之后要调用flush()刷新或者close()关掉才会写入文件! 技术分没什么用的,我现在都不回答问题了;东哥哥,你怎么混起CSDN啦 没有调用flush,调用了flush才会将读取的数据推送。所以楼主在写关于io的代码时,记住一定写flush,有备无患 楼主流的资源需要被关闭。你的代码中读和写的关闭方式为:fw.close(),fr.close(),需要写在finally语句中,在finally语句中还要分别对这两句代码抓异常。写一个文件的时候调用完write方法还不够,这个时候是将写的内容保存到内存缓冲区中,需要用fw对象调用一下flush方法,但是fw对象调用了close方法后,就可以不用调用flush方法了,因为关闭流的close方法在执行时会自动调用flush刷新方法,刷新文件。 import java.io.*;class Text{ public static void main(String args[]){ FileInputStream fis = null; FileOutputStream fos = null; try{ fis = new FileInputStream("e:/src/from.txt"); fos = new FileOutputStream("e:/src/to.txt"); byte [] buffer = new byte [1024]; int temp = fis.read(buffer,0,buffer.length); fos.write(buffer,0,temp); } catch(Exception e){ System.out.println(e); } finally{ try{ fis.close(); fos.close(); } catch(Exception e){ System.out.println(e); } } }}看看这个和你的有什么不同,这个反正输出来了;但这个仅仅限于比较小的文件,如果是大的,还得加个while循环吧!楼主看看? import java.io.*; class Text{ public static void main(String args[]){ FileInputStream fis = null; FileOutputStream fos = null; try{ fis = new FileInputStream("e:/src/from.txt"); fos = new FileOutputStream("e:/src/to.txt"); byte [] buffer = new byte [1024]; int temp = fis.read(buffer,0,buffer.length); fos.write(buffer,0,temp); } catch(Exception e){ System.out.println(e); } finally{ try{ fis.close(); } catch(Exception e){ System.out.println(e); } try{ fos.close(); } catch(Exception e){ System.out.println(e); } } } } 没使用close()关闭,开了就得关 关于传值为地址的一个问题 java安装时报错 刚完成一个项目,功能都完成了,但是效率很低,操作一个小时后基本就要重启下服务器。 如何随机挑选数组中的元素,而且保证每个元素都被选过? 空指针的错误 学习开发java报表的书籍 请教:哪里有rt.jar中以sun开头的package的资料? jsp中出现com.microsoft.sqlserver.jdbc.SQLServerException: 没有为参数号 3 设置值。是怎么回事 开个高级JAVA栏把,这样初级,看好多初级的问题受不了啊 请回答,无比菜的问题! ThreadLocal的缺点 正则表达式堆栈溢出怎么破
public static void main(String args[]){
FileInputStream fis = null;
FileOutputStream fos = null;
try{
fis = new FileInputStream("e:/src/from.txt");
fos = new FileOutputStream("e:/src/to.txt");
byte [] buffer = new byte [1024];
int temp = fis.read(buffer,0,buffer.length);
fos.write(buffer,0,temp);
}
catch(Exception e){
System.out.println(e);
}
finally{
try{
fis.close();
fos.close();
}
catch(Exception e){
System.out.println(e);
}
}
}
}看看这个和你的有什么不同,这个反正输出来了;但这个仅仅限于比较小的文件,如果是大的,还得加个while循环吧!楼主看看?
class Text{
public static void main(String args[]){
FileInputStream fis = null;
FileOutputStream fos = null;
try{
fis = new FileInputStream("e:/src/from.txt");
fos = new FileOutputStream("e:/src/to.txt");
byte [] buffer = new byte [1024];
int temp = fis.read(buffer,0,buffer.length);
fos.write(buffer,0,temp);
}
catch(Exception e){
System.out.println(e);
}
finally{
try{
fis.close();
}
catch(Exception e){
System.out.println(e);
}
try{
fos.close();
}
catch(Exception e){
System.out.println(e);
} }
}
}