copy file using FileReader/Writer.
2014-04-02 13:00
183 查看
The code below demonstates copying file using 'FileReader' and 'FileWriter'.
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:
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:
相关文章推荐
- Csharp:The .dat File using BinaryReader and BinaryWriter Convert to DataTable
- Csharp:The .dat File using BinaryReader and BinaryWriter Convert to DataTable
- FileReader/FileInputStream 和 FileWriter/OutputStream
- 【IO流】FileReader,FileWriter完成文件的copy
- FileReader、FlieWriter分别对InputStreamReader、OutputStreamWriter封装了一个构造方法
- Writing XML File using XmlWriter
- How to copy a datafile from ASM to a file system not using RMAN
- Copy file to output by using attribute: DeploymentItem
- File FileStream StreamWriter StreamReader文件读写操作方法
- 02_IO操作的基本规律(InputStream,OutputStream,Reader,Writer,FileReader,FileWriter,BufferedReader,BufferedWri
- FileWriter&FileReader
- Write to file using a BufferedWriter
- 02_IO操作的基本规律(InputStream,OutputStream,Reader,Writer,FileReader,FileWriter,BufferedReader,BufferedWri
- java FileWriter and FileReader
- 151_IO_字符流_纯文本_节点流_Reader_FileReader_Writer_FileWriter_读取_写出_拷贝
- java使 FileWriter FileReader 无编码格式,OutputStreamWriter InputStreamReader可设置编码格式
- Network File Copy using SSH
- 【Java.IO】I/O 字节 <-> 字符转换流 —— InputStreamReader,OutputStreamWriter(FileReader,FileWriter)
- FileReader&FileWriter
- JAVA IO - FileWriter&FileReader