您的位置:首页 > 运维架构

copy file using FileReader/Writer.

2014-04-02 13:00 183 查看
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:
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: