20110829 日作业,复制文件,简单IO操作,我自己扩展过的,比题干要求的功能多点
2011-08-29 20:11
477 查看
/* * 20110829 日作业 * coded by Younger.shen申延刚 younger.x.shen@gmail.com * blog : blog.csdn.net/hack2me * blog : youngershen.com/blog/ (you should cross GFW to view my sites) * */ import java.util.*; import java.io.*; public class HomeWork1{ private BufferedReader reader = null; private BufferedWriter writer = null; private String fileName = null; private static int start = -1; //private String dumpFileName = null; private ArrayList<String> dumpString = new ArrayList<String>(); public HomeWork1(){ fileName = "./xx.txt"; } public HomeWork1(String path){ fileName = path; } private void gatherString(){ try{ reader = new BufferedReader(new FileReader(fileName)); String temp = reader.readLine(); while(temp != null){ System.out.println(temp); dumpString.add(temp); temp = reader.readLine(); } }catch(IOException e){ System.out.println(e.toString()); }finally{ if(reader!=null){ try{ reader.close(); }catch(IOException e){ System.out.println("IO Error"); } } } } private String getString(int i){ return dumpString.get(i); } public void dumpToFile(){ //reader = new BufferedReader(new FileReader(fileName)); gatherString(); try{ writer = new BufferedWriter(new FileWriter("temp.txt",true)); //System.out.println("i am here"); System.out.println(dumpString.size()); for(int i = 0; i < dumpString.size();i++){ String t = getString(i); // System.out.println("i am 1"); writer.write(t,0,t.length()); writer.write("\r"); writer.write("\n"); // System.out.println("writing"); writer.flush(); } }catch(IOException e){ System.out.println("dump error"); }finally{ try{ writer.close(); }catch(IOException e){ System.out.println("IO Error"); } } } public static void main(String[] args){ if(args.length == 0){ HomeWork1 hw1 = new HomeWork1(); hw1.dumpToFile(); //System.out.println("dumoing"); }else { HomeWork1 hw1 = new HomeWork1(args[0]); hw1.dumpToFile(); } } }
相关文章推荐
- Linux下用文件IO的方式操作GPIO(/sys/class/gpio)简单易操作
- Java学习笔记——File类文件管理及IO读写、复制操作
- IO(C#) 读写文件简单操作
- java中关于I/O文件流的操作实现文件复制和打印功能
- 简单的对文件操作,如复制,读,写
- XML文件作业---实现简单的通讯录功能(XML作为简单数据库)(总结)
- 使用标准io实现文件复制功能
- rcp命令_Linux rcp 命令用法详解:使在两台Linux主机之间的文件复制操作更简单
- 【windows核心编程】IO完成端口(IOCP)复制文件小例前简单说明
- 文件流_File文件操作_功能简单汇总
- 文件的简单操作 : 读、写(覆盖写、追加写)、复制、剪切、新增、删除
- 【IO面试题】文件操作,如何列出某个目录下的所有文件?如何列出某个目录下的所有子目录?写个简单的例子
- java IO 最快文件复制 内存要求较高
- Java-基础 文件操作IO 将文件内容复制到另外一个文件中去
- 通过IO文件流操作实现对文件的复制
- 拖放操作和文件复制小功能
- 使用文件操作函数实现简单的CP、cat、size功能及读取文件内容初始化结构体
- oc 文件管理NSFileManager,文件读写NSFileHandle ,设计一个文件管理类将一个文件复制到另一个文件,由于文件过大要求每次复制100长度,通过NSFileHandle 来操作,并
- 利用Asp.net IO.File类完成文件新建复制删除操作(代码调试通过)(转)
- C#为IO操作补充文件夹复制小功能