CompEng
CompEng

Reputation: 7376

(android)How can I read word in my txt file on android?

I mean that , I write 100 words(every each line contains one word so I write 100 line to 100 word) in a.txt. And I want to acces this txt in my application on android. And for example I only want to 6.word .For this I want to write a function.

public String generate(int a)
{
//I want to return a. word in my txt

//
//
//
//
return ...
}

And I don't know how I do this?

Upvotes: 2

Views: 518

Answers (1)

Vincenzo Pii
Vincenzo Pii

Reputation: 19805

Put the txt in the res/raw folder. Let's say the file is named ff.txt.

Then just open the file as an input stream using the openRawResource() method and providing the resource id as input (e.g.: package.name.here.R.raw.ff).

Once you have the InputStream returned by the openRawResource() method you can do everything you need with the file as you would normally do in a generic java application.

Upvotes: 1

Related Questions