Java Question (Solved - for now) getResourceAsStream

Johan Schoeman

Expert
Licensed User
Longtime User
I am just past stupidly lost with this problem:

1. In a library that I am trying to do a wrapper for there is this line of code:
B4X:
InputStream is = null;
        InputStreamReader isr = null;
        BufferedReader br = null;

        try {
            is = AtrUtils.class.getResourceAsStream("/smartcard_list.txt");
2. The Java project includes a folder called resources and inside this folder is a file called smartcard_list.txt

Where in my B4A project do I need to add the resources folder that contains file smartcard_list.txt ?

I have tried adding it to /Files, /Object/res/raw, but not getting any joy. When I log "is" (=InputStream) it logs "null"
 

drgottjr

Expert
Licensed User
Longtime User
hey, johan -
i think you can simply add the file to the completed jar. then you load the file from the har. i had to
do it with my tesseract library years ago. it definitely worked. erel provded an interesting routine (attached).
see if it makes sense to you.

tesseract's english data file is called eng.traineddata. i simply dragged it into the jar. somebody asked about a problem similar to yours way back sometime.
look here i think that's where it comes from...
 

Attachments

  • 1.png
    5.7 KB · Views: 218
  • johan.txt
    2.5 KB · Views: 236
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
Thanks @drgottjr - have managed to sort it a different way. Have added the smartcard_list.txt to the B4A assets and then used B4A InputStream to get the InputStream and then passed it to the wrapper. In the wrapper I have defined the IPS variable as "static" and can that way use it in the class that is supposed to locate and read smartcard_list.txt. Will send you a PM to test it with - if you can do so please...It reads my Visa card
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…