In my android app I have created a “raw” folder inside /res folder (/res/raw). The “raw” folder contains a file (a public/private key file to connect sftp without password).
I am using Jsch library to connect to sftp using public/private key. For setting the key file I need a path where my key file is. The Jsch method for setting private key file path is:
JSch ssh = new JSch();
ssh.addIdentity("path/to/key/file/filename");
What path should I pass for key file ? Passing “res/raw/filename” gives java.io.FileNotFoundException: /res/raw/firmware_key (No such file or directory)
Then you will need to copy the resource out to a file. There is no file for the resource — it is a bunch of bytes in an APK file. Use
getResources().openRawResource()to get anInputStreamthat you can use to copy the data to a file in internal storage.