The following one-liner can copy very large files without running out of memory:
Just tested it in groovy console - 1 GB file is copied in 5 seconds, memory consumption stays low.
The copy is binary, i.e. it copies bytes, not chars.
One particularity: left-shift operator rather appends than overwrites. If you need to overwrite the file, first need to delete it.
1 | new File("test").withInputStream { new File("test2") << it } |
Just tested it in groovy console - 1 GB file is copied in 5 seconds, memory consumption stays low.
The copy is binary, i.e. it copies bytes, not chars.
One particularity: left-shift operator rather appends than overwrites. If you need to overwrite the file, first need to delete it.
Комментариев нет:
Отправить комментарий