Android Code Snippet Test if a file is a Java Class File

Discussion in 'Code Snippets' started by sonicmayne, Apr 22, 2015.

  1. sonicmayne

    sonicmayne Member Licensed User

    Sub Name: Is Class File

    Description: Determines whether a file looks like it could be a Java Class file (compiled Java code).

    Sub IsClassFile(Path As String, FileName As StringAs Boolean
    If Not(File.Exists(Path,FileName)) OR File.IsDirectory(Path,FileName) Then Return False
    If File.Size(Path,FileName) < 4 Then Return False
    Dim RAF As RandomAccessFile
    Dim result As Boolean = RAF.ReadInt(0) = 0xCAFEBABE
    Return result
    End Sub
    Depends On: RandomAccesFile
    Tags: Class File, Java, File Testing, Magic Numbers

    Note: This also works on B4J.
    thedesolatesoul likes this.
  2. Erel

    Erel Administrator Staff Member Licensed User

    Note that your code snippets will also work in B4i.
    sonicmayne likes this.
  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