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…
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?
[code] 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);
}[/code]
Agradeço a voces
Voces sao fxD
Usa o contains ou o equals?
Tentei isso aqui , nao da certo…
[code] 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);
}[/code]
Resolvido
[code]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();
}[/code]