简体   繁体   中英

extract paragraph from a txt file at SDcard android

I was looking for help as i want to extract a String paragraph from a .txt file from SDcard in adnroid. I have the file but can't extract just a part of it. For example, I have this file:

Mother (mamá)
Father (papá)
Daughter (hija)
Son (hijo)
Sister (hermana)
Brother (hermano)
Grandmother (abuela)
Grandfather (abuelo)
Aunt (tia)
Uncle (tio)
Nephew (sobrino)
Niece (sobrina)
Cousin (primo "o" prima)
Wife (esposa)
Husband (esposo)
NOTA: Al añadir las palabras inglesas "in law" se forman nuevas palabras que tambien deben ser incluidas en este vocabulario para referirnos a "La familia"
Mother in law (*suegra)
Father in law (*suegro)
Sister in law (*cuñaada)
Brother in law (*cuñado)
gual sucede con la palabra "step" antepuesta a algunas palabras inglesas, para referirnos a otro parentesco familiar, resultado de la relacion de nuestros padres con otras parejas (como en el caso de divorcios,muerte de alguno de ellos,etc)
Step mother (*madrastra)
Step father (*padrastro)
Step sister (*hermanastra)
Step brother (*hermanastro)

and just nned to extracto from "Son" until "Niece"

my code is:

String state = Environment.getExternalStorageState();
    TextView tv = (TextView) findViewById(R.id.textView1);
    if (!estado.equals(Environment.MEDIA_MOUNTED)) {
        tv.setText("No SDcard");
        finish();
    }

    File dir = Environment.getExternalStorageDirectory();
    File puntero = new File(dir.getAbsolutePath() + File.separator
            + "manualandroid.txt");
    try {
        Scanner lector = new Scanner(new FileReader(puntero));
        StringBuilder texto = new StringBuilder();
        String linea;
        lv1 = (ListView) findViewById(R.id.listView1);
        while (lector.hasNext()) {
            linea = lector.nextLine();
            if (linea.contains("Son") && linea.contains("Niece") {
                texto.append(linea);
                texto.append("\n");
            }
        }
        lector.close();

    } catch (IOException e) {
        e.printStackTrace();
    }

and it just show me the line that contains "Son" and "Niece", I'm new at this. Can someone help me pleas? y need to read :

Son (hijo)
Sister (hermana)
Brother (hermano)
Grandmother (abuela)
Grandfather (abuelo)
Aunt (tia)
Uncle (tio)
Nephew (sobrino)
Niece (sobrina)

Thanks.

   int withinRange = -1;
   while (lector.hasNext()) {
        linea = lector.nextLine();

        if (linea.contains("Son"))
           withinRange =0;
        if (withinRange == 0) {
            texto.append(linea);
            texto.append("\n");
        }
        if (linea.contains("Niece"))
           withinRange = 1;
   }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM