[RESOLVIDO] Duvida sobre ler .TXT com FLAG

3 respostas
SirDominque

Gente, boa noite... Estou com uma dúvida..
Eu tenho dificuldades pra ler arquivos txt..
Pesquisei e ja sei como ler linha por linha..

Agora é o seguinte, abaixo eu tenho meu TXT...

Start-Titulos End-Titulos Start-Links End-Links

Entre o "Start-Titulos" E "End-Titulos" eu irei gravar várias linhas, aonde cada linha devera ser jogado num arraylist chamado titulos.
Entre o "Start-Links" e "End-Links" eu irei gravar várias linhas, aonde cada linha devera ser jogado num arraylist chamado Links.

Como faço pra ler entre essas palavras chaves? Alguma dica?

public void loadTable() throws FileNotFoundException, IOException {
        ArrayList<String> titulos;
        ArrayList<String> links;

        StringBuilder contents = new StringBuilder();
        BufferedReader reader = null;
        reader = new BufferedReader(new FileReader(notas));
        String text = null;
        
        while ((text = reader.readLine()) != null) 
        {
            contents.append(text).append(System.getProperty("line.separator"));
        }

        mainView.loadTable(null, null);
    }

Agradeço a voces :P
Voces sao fxD

3 Respostas

ViniGodoy

Usa o contains ou o equals?

SirDominque
ViniGodoy:
Usa o contains ou o equals?

Tentei isso aqui , nao da certo..

public void loadTable() throws FileNotFoundException, IOException {
        ArrayList<String> titulos = new ArrayList<>();
        ArrayList<String> links = new ArrayList<>();

        BufferedReader reader = null;
        reader = new BufferedReader(new FileReader(table));
        String text = null;
        
        while ((text) != null) 
        {
            text = reader.readLine();
            
            if (text.equalsIgnoreCase("Start-Titulos")) 
            {
                while (!text.equalsIgnoreCase("End-Titulos")) 
                {
                    text = reader.readLine();
                    titulos.add(text);
                }
            }
            if(text.equalsIgnoreCase("Start-Links"))
            {
                while(!text.equalsIgnoreCase("End-Links"))
                {
                     text = reader.readLine();
                    links.add(text);
                }
            }
            //text = reader.readLine();
        }

        mainView.loadTable(titulos, links);
    }
SirDominque

Resolvido

public void loadNotas() throws FileNotFoundException, IOException {
        FileReader fr = new FileReader(notas);
        //fr.read();

        BufferedReader br = new BufferedReader(fr);
        String text;
        while ((text = br.readLine()) != null) 
        {
            text = text + lineSeparator;
            System.out.println(text);
            mainView.loadNotas(text);
        }
        
        fr.close();
        
    }
Criado 24 de março de 2013
Ultima resposta 24 de mar. de 2013
Respostas 3
Participantes 2