我正在製作一個包含文件複製的應用程序,但是當我瀏覽大型目錄(1000多個)文件並將它們複製到另一個文件夾時,它會使用290+ MB的RAM。在不創建FileOutputStream的情況下複製文件
那麼,有沒有辦法改變File
的FileOutputStream
而不創建FileOutoutStream
類的新實例?
編輯:
這是我的Java 7 API版本。
Path source = FileSystems.getDefault().getPath(Drive.getAbsolutePath(), files[i].getName());
Path destination = FileSystems.getDefault().getPath(Save);
try {
Files.copy(source, destination);
} catch (FileAlreadyExistsException e) {
File file = new File(Save + files[i]);
file.delete();
}
請記住,這是在一個正在測試1000個文件數的循環中。 隨着我使用270+ MB的RAM
你正在關閉你的流? –
哪個版本的Java?理想的答案取決於它。 Java 7有一個新的文件API,比之前的版本要好得多。 – fge
礦是7u21。但使用7u17是一個選項 – zfollette