The code below demonstates copying file using 'FileReader' and 'FileWriter'.

 class CopyV2 extends Timer
{
public void runCode()
{
File fSrc = new File("f.txt");
File fDes = new File("f_des.txt");
Reader r = null;
Writer w = null;
try
{
r = new FileReader(fSrc);
w = new FileWriter(fDes);
int num = -1; //the character read.
while((num = r.read()) != -1)
w.write((char)num);
}
catch (FileNotFoundException e)
{
fDes.delete();
println(e);
}
catch(IOException e)
{ }
finally
{
try
{
if(r != null)
r.close();
}
catch (IOException e)
{
} try
{
if(w != null)
w.close();
}
catch (IOException e)
{
}
}
}
}

upon the code,'Timer' is a class defined by myself,which was used to calculate the elapsed time using 'template method pattern'.

and the figure below simply drawn the relevant steps:

copy file using FileReader/Writer.的更多相关文章

  1. 解决编译报错:Unable to copy file, because it is being used by another process.

    Error    63    Unable to copy file "D:\DEV\XXX Website\trunk\4 Source Code\Common\WebControls\b ...

  2. VS2008 解决Unable to copy file 对路径的访问被拒绝。

    在VS2008 + WINDOWS 7 环境下重新生成解决方案时遇到以下问题 Unable to delete file "F:\XX.exe". 对路径"F:\XX.e ...

  3. 二进制学习——Blob,ArrayBuffer、File、FileReader和FormData的区别

    前言: Blob.ArrayBuffer.File.fileReader.formData这些名词总是经常看到,知道一点又好像不知道,像是同一个东西好像又不是,总是模模糊糊,最近终于下决心要弄清楚. ...

  4. Unable to copy file, Access to the path is denied

    Unable to copy file, Access to the path is denied http://stackoverflow.com/questions/7130136/unable- ...

  5. Java笔记--File,FileInputStream,FileReader,InputStreamReader,BufferedReader 的使用和区别

    转自:http://hi.baidu.com/danghj/item/0ef2e2c4ab95af7489ad9e39 参考资料:  < core java > 12 章 使用 Java ...

  6. File,FileInputStream,FileReader,InputStreamReader,BufferedReader 的使用和区别

    1 ) File 类介绍 File 类封装了对用户机器的文件系统进行操作的功能.例如,可以用 File 类获得文件上次修改的时间移动, 或者对文件进行删除.重命名.换句话说,流类关注的是文件内容,而 ...

  7. ansible copy file

    ansible xxxip  -m copy -a 'src=/localdir/file  dest=/sss/xxx/basic_search/bin/'

  8. Html5——File、FileReader、Blob、Fromdata对象

    File File 接口提供有关文件的信息,并允许网页中的JavaScript访问其内容. File对象可以用来获取某个文件的信息,还可以用来读取这个文件的内容.通常情况下,File对象是来自用户在一 ...

  9. copy file

    import io,,,,,,, from https://pub.dev/packages/large_file_copy Directory directory = await getApplic ...

随机推荐

  1. java or spring +jython +python (Error:python.home,Determine if the following attributes are correct:)

    最近更新 :16年3月10日更 首先你在用JAVA,你需要运行Python,于是你找了Jython,我不介绍什么是Jythyon了 如何在Java中调用Python的方法,一百度一大堆, 如下:是一种 ...

  2. 用F340 GPIO做I2C

    在和Qinheng开发小尺寸点灯治具中,F340和FPGA采用I2C通信,其中F340作为I2C的主机,I2C端口用自己的GPIO编写,总结遇到的问题及注意事项: 1.  F340端口及上拉电阻设置: ...

  3. I2C总线之(三)---以C语言理解IIC

    为了加深对I2C总线的理解,用C语言模拟IIC总线,边看源代码边读波形: 如下图所示的写操作的时序图: 读时序的理解同理.对于时序不理解的朋友请参考“I2C总线之(二)---时序” 完整的程序如下: ...

  4. C++中的new/delete与operator new/operator delete

    new operator/delete operator就是new和delete操作符,而operator new/operator delete是函数. new operator(1)调用opera ...

  5. Java开发手册

    <Java开发手册> 基本信息 作者: 桂颖    谷涛    出版社:电子工业出版社 ISBN:9787121209161 上架时间:2013-8-12 出版日期:2013 年7月 开本 ...

  6. hdu 4717 The Moving Points(三分+计算几何)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4717 说明下为啥满足三分: 设y=f(x) (x>0)表示任意两个点的距离随时间x的增长,距离y ...

  7. thinkphp 获取客户端ip地址方法

    /** * 获取客户端IP地址 * @param integer $type 返回类型 0 返回IP地址 1 返回IPV4地址数字 * @param boolean $adv 是否进行高级模式获取(有 ...

  8. JAVA IO 详解2

    Java 流在处理上分为字符流和字节流.字符流处理的单元为 2 个字节的 Unicode 字符,分别操作字符.字符数组或字符串,而字节流处理单元为 1 个字节,操作字节和字节数组. Java 内用 U ...

  9. DataGridView 添加行 分类: DataGridView 2014-12-07 08:49 263人阅读 评论(0) 收藏

    说明: (1)dgvGoods 是DataGridView名 (2)index 是最大行索引 一. DataGridViewRow row = new DataGridViewRow(); int i ...

  10. eclipse编辑器,怎么创建PHP和JAVA的工程项目?

    eclipse编辑器,怎么创建PHP和JAVA的工程项目.强大的eclipse,编写php或者java由你选择!!! 我为什么这么说? 我是新手,写下这篇文章,可能对新手会有一点点的帮助而已,然后为了 ...