Wednesday 15 June 2011

android - How can I scan through a raw text file? -


I have text files in the raw folder that I would like to use in my app I am using ListFragments and what is the item Depending on the chosen, I want to load that file in a new layout.

I can load the text properly but I want to be able to scan the file first, that I might be the first line of the file is the title that is displayed in the ListView. I have a method that determines the number of files in the raw folder and adds names to ArrayList.

Here's my method:

  Private Zero inventory raw () {field [] field = RORA.clock.Getfield (); For (integer number = 0; count & lt; fields.length; count ++) {myArrayList.add (field [count] .getName ()); }}   

The problem I have is setting up a scanner, I do not know how to tell the scanner to scan this specific file. I tried to create a new file object and used a scanner but I do not think that I am declaring the file name correctly and neither is it the best way to do it. Generally if you know the name of the file, then you can simply:

scanner file reader = new scanner ("filename");

But I have never set the file name in this loop.

I have text files in the raw folder that I would like to use in my app

I'm assuming that "raw folder" means your code in the res / raw / resource directory.

I have to tell the scanner to scan this specific file

It is not because there is no file in it, the file exists on your development machine is. The only raw representation represented on the Runtime is: A raw resource. Under cover, this is effectively an entry in a zip file.

You need to get the R.raw value for a raw resource, then use getResources (). OpenRawResource () to get an InputStream that you can pass through the scanner .

Unless you have different versions of these raw resources, for different configurations (for example, language), you can add assets / for packaging text files with your app. Working with directories and AssetManager can be easy.

No comments:

Post a Comment