Create directory and add files for later browsing on android

2

I'm new to the development area. mobile, I'm developing a simple app that uses the Tesseract-OCR library in Android Studio and I came across the following situation:

I need to store some files in android for a query later.

  • How and when do I record these files on android?
  • After creating this directory with the files, how do I get the path?
asked by anonymous 31.03.2017 / 01:46

1 answer

1

To store various types of files such as .txt, .json, etc, you first need to create an Assets folder , which you will put your archives in.

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

New-> Folder-> Assets Folder

NowthatyouhaveanAssetsFolderjustgointoitanddragthefilesyouwant.Toenteritjustfollowthedirectionsofthenextimage:

Nowyourfilealreadyappearsintheproject.

Toreadthefile,youcandothis:

publicStringloadJSONFromAsset(StringnomeArquivo){Stringjson=null;try{InputStreamis=context.getAssets().open(nomeArquivo);intsize=is.available();byte[]buffer=newbyte[size];is.read(buffer);is.close();Stringtexto=newString(buffer,"UTF-8");
} catch (IOException ex) {
    ex.printStackTrace();
    return null;
}

return texto;
}
31.03.2017 / 02:01