从文件中读取内容
package com.zhiru;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
public class ReadFromFile {
private String fName;
ReadFromFile(String s) {
fName = s;
}
public String read() throws IOException {
if (fName != null) {
File f = new File(fName);
InputStream in = new FileInputStream(f);
byte[] b = new byte[(int) f.length()];
int len = in.read(b);
in.close();
return new String(b, 0, len);
}
return null;
}
}
还没有评论,来说两句吧...