public class ImageTest { public static void main(String[] args) throws IOException { IOTest(); } public static void fileUtilsTest() throws IOException { // 趋近13毫秒后,就保持这个数值 File srcFile = new File("D:/1.apk"); File destFile = new File("E:/2.apk"); long sum = 0; for (int i = 0; i < 10; i++) { long startTime = System.currentTimeMillis(); FileUtils.copyFile(srcFile, destFile); long endTime = System.currentTimeMillis(); sum += (endTime - startTime); } long average = sum / 10; System.out.println("耗时" + average + "豪秒"); } public static void IOTest() throws IOException { // 50毫秒 File srcFile = new File("D:/1.apk"); File destFile = new File("E:/2.apk"); long sum = 0; for (int i = 0; i < 10; i++) { long startTime = System.currentTimeMillis(); InputStream is = new FileInputStream(srcFile); // 把图片写入到上面设置的路径里 OutputStream os = new FileOutputStream(destFile); byte[] buffer = new byte[400]; int length = 0; while ((length = is.read(buffer)) > 0) { os.write(buffer, 0, length); } is.close(); os.close(); long endTime = System.currentTimeMillis(); sum += (endTime - startTime); } long average = sum / 10; System.out.println("耗时" + average + "豪秒"); } } |