1. *** New version of B4J is available ***
    B4J v7.8
    Dismiss Notice

Android Question File.copy, copy is bigger than original...

Discussion in 'Android Questions' started by MitchBu, Jun 17, 2019.

Tags:
  1. MitchBu

    MitchBu Active Member Licensed User

    I want to log PDF files used to print, so I did this after creating 1.pdf :

    Code:
    If File.Exists(File.DirInternal, "1.pdf") = True Then
            
    File.Copy(File.DirInternal,"1.pdf",File.DirDefaultExternal,"Print-" & DateTime.Now & ".pdf")
    End If
    Original (1.pdf) is 21.91 KB
    Copy (Print-1560764371069.pdf) is 39.13 KB

    Both seem to be valid pdf documents.

    Is there any reason to that size difference ?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    It is a mistake to use File.DirDefaultExternal. See the runtime permissions video tutorial.

    What is the output of:
    Code:
    Log(File.Size(File.DirInternal, "1.pdf"))
    Log(File.Size(File.DirDefaultExternal,"Print-" & DateTime.Now & ".pdf"))
     
  3. MitchBu

    MitchBu Active Member Licensed User

    OK. Now I have

    Code:
    If File.Exists(File.DirInternal, "1.pdf") = True Then
            
    Dim f As String = rp.GetSafeDirDefaultExternal("")
            
    Log("safedir: " & f)
            
    File.Copy(File.DirInternal,"1.pdf",F,"Printo-" & DateTime.Now & ".pdf")
    But yet, the copy remains much bigger than the original.
     
  4. DonManfred

    DonManfred Expert Licensed User

    Answering erels question is not worth to give one?
     
  5. MitchBu

    MitchBu Active Member Licensed User

    Code:
    Log(File.Size(File.DirDefaultExternal,"Print-" & DateTime.Now & ".pdf"))

    Result - 
    0
    My question was more of curiosity than anything. Like, for instance, the fact that the copy be bigger than the original could be due to the size of clusters, or something.

    Meh..
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    File.Copy will not change the file size. It is possible that you are seeing some other effect.
    However it is difficult to say more based on the code you posted.
     
    Peter Simpson likes this.
  7. Kiffi

    Kiffi Well-Known Member Licensed User

    @MitchBu : Try this, please

    Code:
    Dim SourceFile As String = "1.pdf"
    Dim TargetFile As String = "Print-" & DateTime.Now & ".pdf"

    If File.Exists(File.DirInternal, SourceFile) = True Then
      
    File.Copy(File.DirInternal, SourceFile, File.DirDefaultExternal, TargetFile)
      
    Log("Size of SourceFile: " & File.Size(File.DirInternal, SourceFile))
      
    Log("Size of TargetFile: " & File.Size(File.DirDefaultExternal, TargetFile))
    Else
      
    Log("SourceFile doesn't exists")
    End If
    Greetings ... Peter
     
    MarkusR likes this.
  8. MarkusR

    MarkusR Well-Known Member Licensed User

    i think i have two reason.
    the file was not overwritten, delete it first and be sure its gone.
    if you look the files at pc, to not trust this virual file system. maybe reboot windows.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice