B4J Library Copy class - Multiple methods to copy a file

I recommend some testing to find out what is best method for your needs.

Every method has it pros and cons that you may want to check from this Stack Overflow thread.

B4X:
BufferedStreamsCopy (Source As String, Target As String) As Boolean

BufferedReaderCopy (Source As String, Target As String) As Boolean

CustomBufferStreamCopy (Source As String, Target As String) As Boolean

CustomBufferReaderCopy (Source As String, Target As String) As Boolean

CustomBufferBufferedStreamCopy (Source As String, Target As String) As Boolean

CustomBufferBufferedReaderCopy (Source As String, Target As String) As Boolean

NioBufferCopy (Source As String, Target As String) As Boolean

NioTransferCopy (Source As String, Target As String) As Boolean
 

Attachments

  • Copy.bas
    7.6 KB · Views: 252
Last edited:

npsonic

Active Member
Licensed User
1. I don't see any reason for these subs to return a ResumableSub. You aren't calling Wait For or Sleep.

2. The best methods for large files are File.CopyAsync or File.Copy2Async. These two methods will not block the main thread.
Removed ResumableSubs, also done some testing and almost every method is exactly as fast as File.Copy, but NioTransferCopy seems to be about 2 times faster than File.Copy. I did all test with ~500MB file from one hdd to another.
 
Last edited:
Top