loadtext.java
来自「PIY(Program It Yourself)是一个基于Java的应用程序开发」· Java 代码 · 共 35 行
JAVA
35 行
package piy.action;
import piy.PIYAction;
import piy.FixedProperty;
import java.io.*;
/**
* Loads text from a file into a String object, then returns the string.
*
* @author David Vivash
* @version 1.0, 28/04/01
*/
public class LoadText implements PIYAction, Serializable {
private FixedProperty loadFrom = new FixedProperty(null, File.class);
public FixedProperty getLoadFrom() { return loadFrom; }
public void setLoadFrom(FixedProperty file) { loadFrom = file; }
public Class getReturnType() { return String.class; }
public Object execute() {
byte[] text = null;
try {
FileInputStream input = new FileInputStream((File)loadFrom.getActualValue());
input.read(text = new byte[input.available()]);
input.close();
} catch (Exception e) {
System.out.println("Couldn't load text file: " + loadFrom);
}
return new String(text);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?