wood burning stoves 2.0*
The moose likes Android and the fly likes how to view all the names that exists in the file using an scroll or trying the name in emulator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "how to view all the names that exists in the file using an scroll or trying the name in emulator" Watch "how to view all the names that exists in the file using an scroll or trying the name in emulator" New topic

how to view all the names that exists in the file using an scroll or trying the name in emulator

deepika deepi
Ranch Hand

Joined: Jan 23, 2012
Posts: 199
i want to get the whole output that exists in the file from an external memory. but i am able to view only few files from first till the emolator is displayed. how can i make it view all the file that exists in the file using an scroll and search option for that external storage?

android code is

[code = android]

package com.lightcone.writesdcard;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.widget.TextView;

public class WriteSDCard extends Activity {

private static final String TAG = "MEDIA";
private TextView tv;

/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
tv = (TextView) findViewById(R.id.TextView01);

/** Method to check whether external media available and writable. This is adapted from
http://developer.android.com/guide/topics/data/data-storage.html#filesExternal */

private void checkExternalMedia(){
boolean mExternalStorageAvailable = false;
boolean mExternalStorageWriteable = false;
String state = Environment.getExternalStorageState();

if (Environment.MEDIA_MOUNTED.equals(state)) {
// Can read and write the media
mExternalStorageAvailable = mExternalStorageWriteable = true;
} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
// Can only read the media
mExternalStorageAvailable = true;
mExternalStorageWriteable = false;
} else {
// Can't read or write
mExternalStorageAvailable = mExternalStorageWriteable = false;
tv.append("\n\nExternal Media: readable="
+mExternalStorageAvailable+" writable="+mExternalStorageWriteable);

/** Method to write ascii text characters to file on SD card. Note that you must add a
WRITE_EXTERNAL_STORAGE permission to the manifest file or this method will throw
a FileNotFound Exception because you won't have write permission. */

private void writeToSDFile(){

// Find the root of the external storage.
// See http://developer.android.com/guide/topics/data/data-storage.html#filesExternal

File root = android.os.Environment.getExternalStorageDirectory();
tv.append("\nExternal file system root: "+root);

// See http://stackoverflow.com/questions/3551821/android-write-to-sd-card-folder

File dir = new File (root.getAbsolutePath() + "/download");
File file = new File(dir, "myData.txt");

try {
FileOutputStream f = new FileOutputStream(file);
PrintWriter pw = new PrintWriter(f);
pw.println("Howdy do to you.");
pw.println("Here is a second line.");
} catch (FileNotFoundException e) {
Log.i(TAG, "******* File not found. Did you" +
" add a WRITE_EXTERNAL_STORAGE permission to the manifest?");
} catch (IOException e) {
tv.append("\n\nFile written to "+file);

/** Method to read in a text file placed in the res/raw directory of the application. The
method reads in all lines of the file sequentially. */

private void readRaw(){
tv.append("\nData read from res/raw/textfile.txt:");
InputStream is = this.getResources().openRawResource(R.raw.textfile);
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr, 8192); // 2nd arg is buffer size

// More efficient (less readable) implementation of above is the composite expression
/*BufferedReader br = new BufferedReader(new InputStreamReader(
this.getResources().openRawResource(R.raw.textfile)), 8192);*/

try {
String test;
while (true){
test = br.readLine();
// readLine() returns null if no more lines in the file
if(test == null) break;
tv.append("\n"+" "+test);
} catch (IOException e) {
tv.append("\n\nThat is all");


. how to make this option available for this code ?

[Thumbnail for external-storage.jpg]

Swastik Dey

Joined: Jan 08, 2009
Posts: 1474

It would be better to use a ListView in this case. You don't have to keep appending the data to the text view. Keep storing the data in some array. Use this array in setAdapter method of listview

wood burning stoves
subject: how to view all the names that exists in the file using an scroll or trying the name in emulator