B4J Question B4J File downloaded, move instead of copy

coyote

Member
Licensed User
Longtime User
Hi,

is it possible to move a file instead of copy it?
The file I downloaded is huge ( > 4 GB). When the job is finished the file will be copied.
But it takes too long.

B4X:
Dim out AsOutputStream = File.OpenOutput(...) 'target folder
File.Copy2(Job.GetInputStream, out)
out.Close

Is it possible to do something like File.Move(Job.GetInputStream, out)?
Or can I change the Temp File Location before I start the download process?

Thanks,

Coyote
 

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi,

an option is to rename the file stored in the temp folder. This is an example using JavaObjects (requires JavaObject Library).

B4X:
' Rename a file - Path can contain full and different path, which would be the same as moving a file
' Class Reference: http://docs.oracle.com/javase/8/docs/api/java/io/File.html
Sub renameFile(source As String, target As String)
    Dim joFileSource As JavaObject
    Dim joFileTarget As JavaObject
    ' Create the file instances for the files (the constructor)
    joFileSource.InitializeNewInstance("java.io.File", Array As Object(source))
    joFileTarget.InitializeNewInstance("java.io.File", Array As Object(target))
    ' Rename source file to target file
    joFileSource.RunMethod("renameTo", Array As Object(joFileTarget))
End Sub

Example renaming = "moving"
B4X:
renameFile(File.DirTemp & "\testfile.txt", File.DirApp & "\testfile.new")
 
Upvote 0
Top