i have generated an code for calling an file and it works fine. now i have different names that exists in an file. i want to declare that in that file and when i enter that number i want to display that name alone in the output
the text file look like this
apple
------------
mango
-------------
pineapple
-------------
jackfruit
-------------
papaya
-------------
grapes
------------
gauva
-----------
i want to get selective output displaying only one
word. can any one illustrate with an example for an file access?
and i want to declare apple [0], mango[1] and so on till gauva[6]
when i enter 6 it should display guava alone. can any one give some examples how to declare that for an file?
the code is
package com.javasamples;
//reading an embedded RAW data file
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
import java.io.*;
public class FileDemo1Activity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
PlayWithRawFiles();
} catch (IOException e) {
Toast.makeText(getApplicationContext(),
"Problems: " + e.getMessage(), 1).show();
}
}// onCreate
public void PlayWithRawFiles() throws IOException {
String str="";
StringBuffer buf = new StringBuffer();
InputStream is = this.getResources().openRawResource(R.drawable.my_base_data);
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
if (is!=null) {
while ((str = reader.readLine()) != null) {
buf.append(str + "\n" );
}
}
is.close();
Toast.makeText(getBaseContext(),
buf.toString(), Toast.LENGTH_LONG).show();
}// PlayWithSDFiles
} // FilesDemo4
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>