B4J Question How do I resolve the simple function MoveFile in B4J

johnerikson

Active Member
Licensed User
Longtime User
I try to move a file to another directory, but have problems to remove the copied file, the Java platform has it open after the copy, how do I solve this problem???

B4X:
'WebSocket class
public Sub MoveFile (sSourceDir As String, sDestDir As String, sFile As String) As Boolean
    Dim bOK As Boolean
    Try
        File.Copy(sSourceDir,sFile, sDestDir, sFile)
    Catch
        Return False
    End Try   
   
    bOK = File.Delete( sSourceDir, sFile)
    Return bOK
  
End Sub
 

johnerikson

Active Member
Licensed User
Longtime User
Thanks!
It is just as you say, the problem is somewhere else, I think I found it!

I read all the files (Images) from a directory to a list. This list is used for viewing images on screen, do selection of images for editing and so on. One function is to move images to other directors (category ).

I think the problem is that after reading the images to the list, they are kept open. I can see this among other things in Windows Explorer!
If I try to delete the file in Windows Explorer, I get the following message:
The message below is in Swedish as picture, it says:

“ The file is used
the operation cannot be completed because the file is open in the Java ™ Platform SE binary
Close the file and try again.”

I need to change the strategy for moving files and simultaneously visualize the movement on screen!
I guess I can't close files in runtime!
 

Attachments

  • Skärmklipp.JPG
    Skärmklipp.JPG
    29.6 KB · Views: 198
Upvote 0

johnerikson

Active Member
Licensed User
Longtime User
Thanks that good to know, but I use Alains ABMaterial ABMCard to show the images on screen.
They would perhaps be Alain using the Image.Initialize2 method.

I have also tried with below code, but with same result!
B4X:
    Dim inpStream As InputStream
    inpStream = File.OpenInput(sSourceDir, sFile)
     
    Dim outStream As OutputStream
    outStream = File.Openoutput(sDestDir, sFile, False)
    File.Copy2(inpStream, outStream)
   
    outStream.Close
    inpStream.Close

    Try
        bOK = File.Delete( sSourceDir, sFile)
    Catch
        Return False
    End Try
    Return bOK

I working on a new strategy!
 
Upvote 0

johnerikson

Active Member
Licensed User
Longtime User
EUREKA!
The problem is solved.
I have done a own Class for solving Exif code as returns Image information (date, GPS data etc.)!
The image I used for testing had no GPS data or date info, it caused a return without closing the inputstream that was opened!
So it was my own fault!!
Erel, your comment 'The problem is probably somewhere else' was true!
I´m sorry to disturbed you with incorrect programming!
In all cases, Anyway
THANKS!!
 
Upvote 0
Top