繁体   English   中英

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

[英]extract paragraph from a txt file at SDcard android

我一直在寻求帮助,因为我想从adnroid的SDcard的.txt文件中提取String段落。 我有文件,但不能提取其中的一部分。 例如,我有这个文件:

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)

刚从“ Son”提取到“ Niece”

我的代码是:

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();
    }

它只是向我显示包含“ Son”和“ Niece”的行,这是我的新手。 有人可以帮助我吗? 您需要阅读:

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

谢谢。

   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