[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之间。
我想说的是InputStreamReader是[b]可以指定编码方式的[/b]
InputStreamReader
不明白你的意思。你现在做的是
1. 读入InputSteam到一个byteArray
2. 将此byteArray用指定编码变成String
而InputStream则是直接用内置的方法读入InputStream成String
注意,InputStream是[b]可以指定编码方式的[/b]。