[code="java"]File file = new File(path);
try {
if (!file.exists() || file.isDirectory())
throw new FileNotFoundException();
BufferedInputStream in = new BufferedInputStream(
new FileInputStream(file));
ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
byte[] temp = new byte[1024];
int size = 0;
while ((size = in.read(temp)) != -1) {
out.write(temp, 0, size);
}
in.close();
String encod_char = findCharSet(out.toString());
return out.toString(encod_char);
} catch (IOException ie) {
ie.printStackTrace();
}
return null;[/code]
这个是我写的一个读取文件的方法,不知道还有没有更高效的算法。还请大家赐教。。。。执行效率大约在30-50MS之间。