简体   繁体   English

从SDcard android的txt文件中提取段落

[英]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. 我一直在寻求帮助,因为我想从adnroid的SDcard的.txt文件中提取String段落。 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" 刚从“ Son”提取到“ 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. 它只是向我显示包含“ Son”和“ Niece”的行,这是我的新手。 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;
   }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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