可能重复:
Any way to improve the performance for reading a file ,better than buffered reader
我正在阅读一个名为ty.log的文件,它通过缓冲读卡器是20 mb请告知如何通过NIO读同样的东西..Below是我的程序请告诉我如何转换,以便我可以阅读相同的文件通过java nio也在jdk 1.6下
public static void main(String[] args)
{
BufferedReader br = null;
long startTime = System.currentTimeMillis();
try
{
String sCurrentLine;
br = new BufferedReader(new FileReader("C://ty.log"));
while ((sCurrentLine = br.readLine()) != null)
{
}
long elapsedTime = System.currentTimeMillis() - startTime;
System.out.println("Total execution time taken in millis: " + elapsedTime);
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
try
{
if (br != null)
br.close();
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
}