Create directory and add files to query later on android

Asked

Viewed 825 times

3

I am new in the area of Development. mobile, I am developing a simple app that uses the library Tesseract-OCR in Android Studio and I came across the following situation:

I need to store some files on android p/query them later.

  • How and when I record these files on android?
  • After creating this directory with the files, how do I get the path?
  • I never had to use it, but check out this tutorial if it helps: http://www.codepool.biz/making-an-android-application-with-tesseract.html

  • @Acklay I’ll take a look, but I’m doing a lot of research already on how to use Tesseract in windows with android-studio, in the vast majority of tutorials is in linux and eclipse, I’ve already made enough progress, I’m already able to use Tesseract, missing some last settings, calibrate etc... The main functionality already works, the problem is that I added these files I need to sdcard manually, so the question, thank you.

2 answers

2


To store various types of files such as . txt, . json, etc, you first need to create a Assets Folder, That’s where you’ll put your files.


to create a Assets Folder just click on your projectile with the right mouse button and follow this path:

New->Folder->Assets Folder

inserir a descrição da imagem aqui


Now that you have a Assets Folder just enter it and drag the files you want. To enter it just follow the guidelines of the next image:

inserir a descrição da imagem aqui


Now your file already appears in the projectile.

inserir a descrição da imagem aqui


To read the file, you can do this way:

public String loadJSONFromAsset(String nomeArquivo) {
String json = null;
try {
    InputStream is = context.getAssets().open(nomeArquivo);
    int size = is.available();
    byte[] buffer = new byte[size];
    is.read(buffer);
    is.close();
    String texto = new String(buffer, "UTF-8");
} catch (IOException ex) {
    ex.printStackTrace();
    return null;
}

return texto;
}

  • 1

    As soon as possible I will test, put the feedback here, if it works I accept the RE, thank you from now.

  • I’m sorry, but what does this have to do with the Tesseract-OCR library ?

  • 1

    @Acklay The questioner did not ask for information on how to use the Tesseract, but how to save data to a folder, which has already been answered.

  • @Luc , I’m sorry, I said the answer is wrong?

  • 2

    Calm down, it’s all right, @Acklay didn’t say at any point that she was wrong, just asked what she had to do with it. Luc answered simply in a very direct way, anyway, thanks to all involved, it worked here. And by the way Ack Lay, thinking about creating a question on how to configure and use Tesseract in detail here at stackoverflow with reward, I’ll just think of a p/not get too comprehensive shape, you think it fits the stack scope?

  • @Acklay, Ope. That’s not what I meant. It was because your question seemed to say that the questioner had asked about the Tesseract...

  • @Mathias has yes, you can ask! :)

Show 2 more comments

1

Gee, it helped me a lot. I was trying to create a normal folder and throw the files in there. Then Inputstream always returned null. Hence, creating this folder Assets, gave right. My idea is to put in it several figures and dynamically recover based on an object. Look how you got:

if(!(questao.getImagem()==null || questao.getImagem().isEmpty())){
            InputStream is = null;
            try {
                is = context.getAssets().open(questao.getImagem());//"vestibular1questao5.jpeg");
                imagemQuestao.setImageDrawable(Drawable.createFromStream(is, ""));
                imagemQuestao.setAdjustViewBounds(true);
                imagemQuestao.setScaleType(ImageView.ScaleType.FIT_XY);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.