如果使用:
int ch;
while ( (ch = bufferedReader.read()) != -1) {
stringBuffer.append( (char) ch);
}
stringBuffer.toString()速度有所提高(差不得等10秒),但还是不能根本解决问题.
int ch;
while ( (ch = bufferedReader.read()) != -1) {
stringBuffer.append( (char) ch);
}
stringBuffer.toString()速度有所提高(差不得等10秒),但还是不能根本解决问题.
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;public class BigString {
public static void main(String[] args) throws IOException {
FileChannel fc = new RandomAccessFile("manual.html", "r").getChannel();
ByteBuffer bb = ByteBuffer.allocate((int) fc.size());
fc.read(bb);
long start = System.currentTimeMillis();
String bigStr = new String(bb.array(), "UTF-8");
long end = System.currentTimeMillis();
System.out.println("cost: " + (end - start) + "ms");
}
}测试文件选用 MySQL 的 manual.html(3MB) 文件
Athlon 2500+ 耗时 203 毫秒
真不知道 MySQL 怎么想的...
mysql的文档本来就挺烂的