title: Can java JNI load native funciton without file?
body: <p>I'm wondering how to write a java program that load native funciton from itself.
  I just want to use the simple native function in lib(which raw data was stored inside java code).</p>
  <p>Usually load native is like this, which will load lib from file system:</p>
  <pre class="lang-java prettyprint-override"><code>public class HelloJNI {
     static {
        System.loadLibrary(&quot;hello&quot;); // Load native library hello.dll (Windows) or libhello.so (Unixes)
     }
     private native void sayHello();
  
     public static void main(String[] args) {
        new HelloJNI().sayHello();
     }
  }
  </code></pre>
  <p>However for some reason, I want do this with only one .java file. For example, I write &quot;libhello.so&quot; from java to file and load it:</p>
  <pre class="lang-java prettyprint-override"><code>public class HelloJNI  {
      public static native void sayHello();
  
      public static void main(String[] args) throws Exception{
          FileOutputStream fos = new FileOutputStream(&quot;./libhello.so&quot;);
          fos.write(Base64.getDecoder().decode(&quot;base64encode of libhello.so&quot;));
          fos.close();
          System.load(System.getProperty(&quot;user.dir&quot;)+&quot;/libhello.so&quot;);
          new HelloJNI().sayHello();
  
      }
  }
  </code></pre>
  <p>Since I write data in program to file and load the file I just wrote only to use &quot;System.load()&quot;, I want to know if I can just load from program rather than write to file and load it.</p>