Ioutils.getstringfromreader () read mode is the fastest
InputStream in = null;
String line = "";
Long start=0,end=0;
try {
Start = System.currenttimemillis ();
in = new FileInputStream (New File ("D://1.txt"));
InputStreamReader stream = new InputStreamReader (in, "GBK");
char[] temp = new char[1024];
int count = 0;
while ((count = Stream.read (temp))! =-1) {
Line = line + new String (temp, 0, count);
}
End = System.currenttimemillis ();
System.err.println (line);
System.err.println (End-start);
In.close ();
} catch (FileNotFoundException e) {
SYSTEM.ERR.PRINTLN ("File not Found");
} catch (IOException e) {
SYSTEM.ERR.PRINTLN ("io read inconsistent");
}
try {
Long Start1 = System.currenttimemillis ();
InputStream in1 = new FileInputStream (New File ("D://1.txt"));
BufferedReader br = new BufferedReader (new InputStreamReader (in1, "GBK"));
String s= "";
char[] temp = new char[1024];
int count=0;
while ((Count=br.read (temp))! =-1) {
s + = new String (temp, 0, count);
}
In1.close ();
Br.close ();
Long end1 = System.currenttimemillis ();
System.out.println (s);
System.out.println ((End-start) + "ReadLines" + (END1-START1));
Long Start2=system.currenttimemillis ();
InputStream in2 = new FileInputStream (New File ("D://1.txt"));
String Is=ioutils.getstringfromreader (New BufferedReader (New InputStreamReader (in2, "GBK"));
System.err.println (IS);
Long End2=system.currenttimemillis ();
System.out.println ((End-start) + "ReadLines" + (END1-START1) + "test" + (END2-START2));
} catch (FileNotFoundException e) {
SYSTEM.OUT.PRINTLN ("File not Found");
} catch (IOException e) {
SYSTEM.OUT.PRINTLN ("io read inconsistent");
}
Java Read file contents three forms and comparison of efficiency