50-Commons IO

43 阅读1分钟
调用read,write,提高效率定义数组,或者用缓冲流非常麻烦 
   Commons-IO: 简化IO流的操作的  Commons-DBUtils: 简化JDBC操作的 
   IOUtils  copy(InputStream is,OutputStream os): 复制文件的
          closeQuietly(...): 关闭资源,内部帮助我们处理异常
          copyDirectoryToDirectory(File srcDir,File destDir): 拷贝文件夹
          writeStringToFile(File file,String str): 写字符串到文本文件中。
           readFileToString(File file): 读取文本文件,返回字符串。
 */
public class Demo05CommonsIO {
    public static void main(String[] args) throws IOException {
        IOUtils.copy(
                		new FileInputStream("day12_xw\\copyfrom\\cxyjzc.flv"),
                		new FileOutputStream("day12_xw\\copyto\\cxyjzc.flv")
        		    );

        FileUtils.copyDirectoryToDirectory(
                								new File("day12_xw\\io"),
                								new File("day12_xw\\io2")
        								  );

        FileUtils.writeStringToFile(
                						new File("day12_xw\\commons.txt"),
                						"原来IO流的使用如此之简单"
        						   );

        String str = FileUtils.readFileToString(new File("day12_xw\\commons.txt"));
        System.out.println(str);        
    }
}