当前位置:七道奇文章资讯编程技术Java编程
日期:2011-03-22 16:13:00  来源:本站整理

Jakarta-Common-IO操纵笔记[Java编程]

赞助商链接



  本文“Jakarta-Common-IO操纵笔记[Java编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:

代码以下:

A.文件内容拷贝

package demo;

import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Writer;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;

public class FileCopyExample ...{

  public static void main(String[] args) ...{
    try ...{
      File src = new File("test.dat");
      File dest = new File("test.dat.bak");

      FileUtils.copyFile(src, dest);
    } catch (IOException ioe) ...{
      System.out.println("Problem copying file.");
    }

    try ...{
      File src = new File("test.dat");
      File dir = new File("./temp");

      FileUtils.copyFileToDirectory(src, dir);
    } catch (IOException ioe) ...{
      System.out.println("Problem copying file to dir.");
    }

    try ...{
      String string = "Blah blah blah";
      File dest = new File("test.tmp");

      FileUtils.writeStringToFile(dest, string, "ISO-8859-1");
    } catch (IOException ioe) ...{
      System.out.println("Error writing out a String.");
    }

    try ...{
      Writer writer = new FileWriter("test.dat");
      InputStream inputStream = FileCopyExample.class.getClass()
          .getResourceAsStream("/demo/web.xml");
      IOUtils.copy(inputStream, writer);
      writer.close();
      inputStream.close();
    } catch (IOException e) ...{
      System.out.println("Error copying data");
    }

    try ...{
      File src = new File("test.txt");
      OutputStream output = new FileOutputStream(src);
      InputStream inputStream = FileCopyExample.class.getClass()
          .getResourceAsStream("/demo/web.xml");
      IOUtils.copy(inputStream, output);
      // writer.close();
      inputStream.close();
      output.close();
    } catch (IOException e) ...{
      System.out.println("Error copying data");
    }
  }
}


  以上是“Jakarta-Common-IO操纵笔记[Java编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:

  • Jakarta Struts操纵的七个经验
  • Jakarta-Common-Math操纵笔记
  • Jakarta-Common-JXPath操纵笔记
  • Jakarta-Common-IO操纵笔记
  • Jakarta-Common-Digester操纵笔记
  • <b>Jakarta-Common-Configuration操纵笔记</b>
  • Jakarta-Common-Codec操纵笔记
  • <b>Jakarta-Common-CLI操纵笔记</b>
  • Jakarta-Common-Chain操纵笔记
  • Jakarta-Common-BetWixt操纵笔记
  • Jakarta-Common-BeanUtils操纵笔记
  • 本文地址: 与您的QQ/BBS好友分享!
    • 好的评价 如果您觉得此文章好,就请您
        0%(0)
    • 差的评价 如果您觉得此文章差,就请您
        0%(0)

    文章评论评论内容只代表网友观点,与本站立场无关!

       评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论
    Copyright © 2020-2022 www.xiamiku.com. All Rights Reserved .