function.java

来自「一个用Java成功实现的词发分析工具」· Java 代码 · 共 71 行

JAVA
71
字号
package hartech.kids.fileKits;

import java.io.*;
import hartech.J;

/**
 * <p>Title: TransformFile To ClipBoard</p>
 *
 * <p>Description: </p>
 *
 * <p>Website: www.hartech.cn </p>
 * <p>Page: http://www.hartech.cn/blog/blogview.asp?logID=86 </p>
 * <p>Date: 2006-08-30 </p>
 */
public class Function {

  public static String transformFile(String src) {
    return transformFile(new File(src));
  }

  public static String transformFile(File src) {
    String lineStr, string = "";
    StringBuffer sb = new StringBuffer();
    int i = 0;
    BufferedReader in = null;
    try {
      in = new BufferedReader(new FileReader(src));
      while ( (lineStr = in.readLine()) != null) {
        // add transform codes here
        // line by line
        // eg. String lineStr=function(lineStr)
        i = 0;
        if (!lineStr.equals("")) {
          while (lineStr.charAt(i) == J.SPACEC) {
            lineStr = lineStr.replaceFirst(J.SPACES, J.TABS);
            i++;
          }
        }
        // code end
        sb.append(lineStr + "\r\n");
      }
      string = "Transform File is done: \r\n\r\nFrom:    " + src +
          "\r\nTo:         ClipBoard";
      //J.p(string);
    }
    catch (FileNotFoundException ex) {
      string = "File Not Found!";
      J.pw(string);
    }
    catch (IOException ex) {
      string = "IO exception!";
      J.pw(string);
    }
    finally {
      try {
        in.close();
      }
      catch (IOException ex) {
        string = "IOException when closing!";
        J.pw(string);
      }
      J.stringToClipBoard(sb.toString());
      return string;
    }
  }

  public static void main(String[] args) {
    transformFile("E:/JProject/scr/hartech/Ooop.java");
  }
}

⌨️ 快捷键说明

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