fileoption.java

来自「wincvs 的使用配置的东西」· Java 代码 · 共 88 行

JAVA
88
字号
/* **************************************************************** *//* System Name : 億乕僞儖仌僌儖乕僾僂僄傾僾儘僕僃僋僩 * File   Name : UID堦尦娗棟楢摦僷僗儚乕僪曄峏  (FileOption.java) * Compiler    : JDK 1.5.0 * Description : 僼傽僀儖張棟僋儔僗 * ---------------------------------------------------------------- * Modification History * Date         Name            Description * -----------  --------------  ----------------------------------- * 2007/11/XX                   Initial Release * ---------------------------------------------------------------- *//* **************************************************************** */package common;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.InputStream;import java.nio.ByteBuffer;public class FileOption {  private String sFilePath;  //  private String sContent;   //  /* **********************************************************************   * 僼傽僀儖僐僺乕張棟   * @param String 擖椡僼傽僀儖   * @param String 弌椡僼傽僀儖   * @return boolean 僼傽僀儖僐僺乕寢壥   * @throws exception Exception 幚峴帪僄儔乕   * @version  *************************************************************************/  public boolean copyFile(String s1, String s2) {    int bytesum = 0;    int byteread = 0;    try {      InputStream inStream = new FileInputStream(s1);      FileOutputStream fs = new FileOutputStream(s2);      byte[] buffer = new byte[1444];      while ((byteread = inStream.read(buffer)) != -1) {        bytesum += byteread;        fs.write(buffer, 0, byteread);      }      inStream.close();      fs.close();      return true;    } catch (Exception e) {        return false;    }  }  /* **********************************************************************   * 僶僀僫儕偱僼傽僀儖撪梕傪捛壛張棟   * @param String 擖椡僼傽僀儖   * @param String 捛壛撪梕   * @return boolean 捛壛寢壥   * @throws exception Exception 幚峴帪僄儔乕   * @version  *************************************************************************/  public boolean appendFileByByte(String s1, byte[] b) {    sFilePath = s1;    sContent += "\n";    File myFilePath = new File(sFilePath);    FileOutputStream fw;    try {      if (!myFilePath.exists()) {        //create file and add content        fw = new FileOutputStream(sFilePath);      }      else {        //append to file        fw = new FileOutputStream(sFilePath,true);      }      fw.write(b);      fw.close();      return true;    } catch (Exception e) {      e.printStackTrace();      return false;    }  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?