クローブ:
このコードは、大きなファイルをコピーする時に遅く、遅く動作します。私は何かを間違っているのでしょうか?
InputStream ms2 = new BufferedInputStream(new FileInputStream("/home/fedd/Videos/homevid.mp4"));
OutputStream fos2 = new BufferedOutputStream(new FileOutputStream("testfile2.mp4", true));
try {
int byt;
int i = 0;
long time = System.currentTimeMillis();
while ((byt = ms2.read()) != -1) {
fos2.write(byt);
i++;
if (i > 100000) {
i = 0;
long took = System.currentTimeMillis() - time;
System.out.println("100000 bytes took " + took + " milliseconds which means " + (100000000 / took) + " bytes per second");
}
}
fos2.close();
ms2.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
私のJavaは次のとおりです。
OpenJDKの10.0.2 2018年7月17日のOpenJDKランタイム環境(ビルド10.0.2 + 13-Ubuntuの-1ubuntu0.18.04.4)
OpenJDKの64ビットサーバーVM(ビルド10.0.2 + 13のUbuntu-1ubuntu0.18.04.4、混合モード)
Ekamjitシン:
あなたはそれぞれの比較の後にお使いのベース「時間」をリセットする必要があります。これを使用してみてください:
if (i > 100000) {
i = 0;
long took = System.currentTimeMillis() - time;
time = System.currentTimeMillis();
System.out.println("100000 bytes took " + took + " milliseconds which means " + (100000000 / took) + " bytes per second");
}