Como fazer p/ excluir um nome de uma lista de arquivo

Galera, é o seguinte…

Estou fazendo uma leitura de um arquivo TXT........................  blz
Depois de aberto, consigo incluir novos nomes nesse arquivo... blz
Imprimo essa lista no video com tdos os nomes...................... blz

Mas agora, como q faço p/ deletar(excluir) um nome dessa lista, ou seja, eu entro com um nome, preciso verifiicar se esse existe no meu arquivo e ai, deletar ele, como fazer isso??? E a msma coisa, tb para eu poder altera-lo… Creio q seja da msma maneira…

Sei q para gravar um novo nome, faço out.write, mas nem tenho ideia de como fazer p/ excluir e alterar… preciso comparar o nome com os nomes da lista p/ ver se verdade, mas como fazer isso??

aguardo galera, e brigadao msmo…

to ficando bom em java… é show tdo isso… aguardo… :frowning:

creio eu q vc terá q escrever tudo denovo =]

\o/

vai ter q mandar ele ir gravando… e não mandar gravar a linha q vc naum quer…

MASS… axo que tem algo que talvez seja melhor pra vc…

vamos ao caso…

java.util.Proprietes

uma otima classe… com ela vc pode ler um arquivo assim…

arquivo.txtlinhas=10 titulo=meu maravilhoso teste comentario=vc pode criar quantas propriedades quizer 1=dado da key 1 2=dado da key 2 ... 10=dado da key 10

bom com isso ai… vc depois le isso bem facinho… só fazer

[code]java.io.Proprietes file = new java.io.Proprietes();
file.load(new java.io.FileInputStream("pasta/onde/ta/o/arquivo/arquivo.txt"));

//agora pra usar só fazer

System.out.prinln(file.getPropety("titulo"));
System.out.prinln(file.getPropety("comentario"));
System.out.prinln(file.getPropety("1"));
System.out.prinln(file.getPropety("10"));

//pra alterar só fazer
file.setPropety("titulo","meuNovo Tiutulo");

//ai depois q acabou de alterar… vc salva assim

file.save();
//ou é
file.store();
//ou talvez os 2 funfe…[/code]

boa sorte[/code]

e ae tomaz, blz… kra, fiz o q vc me passow, mas como nunca havia visto isso, veja só q erro ele deu??


  import java.io.*;
import java.util.*;

public class Ju {

	static public void main (String[] args)
	 {
	   try {
	   		java.io.Proprietes file = new java.io.Proprietes();
			file.load(new java.io.FileInputStream("arquivo.txt"));

			//agora pra usar só fazer

			System.out.prinln(file.getPropety("titulo"));
			System.out.prinln(file.getPropety("comentario"));
			System.out.prinln(file.getPropety("1"));
			System.out.prinln(file.getPropety("10"));

			//pra alterar só fazer
			file.setPropety("titulo","meuNovo Titulo");

			//ai depois q acabou de alterar... vc salva assim

			file.save();
			//ou é
	//		file.store();
			//ou talvez os 2 funfe....

			} catch (Exception e) {}
}
}

e agora, na hra de compilar, veja as msg de erro:

-Called Compiler C:\J2SDK1~1.1_0\bin\javac.exe-
-Target File: C:\tt\Ju.java-
C:\tt\Ju.java:9: cannot resolve symbol
symbol : class Proprietes
location: package io
java.io.Proprietes file = new java.io.Proprietes();
^
C:\tt\Ju.java:9: cannot resolve symbol
symbol : class Proprietes
location: package io
java.io.Proprietes file = new java.io.Proprietes();
^
2 errors

-Finished-

q q eu posso fazer p/ arrumar isso?? o pq q ele nao esta compilando, qual o erro,… aguardi e valews msmo desde ja…

aguardo…
8O

java.util.Properties
e nào
java.io.Properties

c eu falei java.io … foi mau ai =]

mas é util

outra coisa… troca a la a parte onde tem…

file.save e file.store … por

file.store(new java.io.FileOutputStream(“arquivo.txt”),“Tituo”);

t +

kra, olha os erros agora, confira o codigo… ah e uma coisa, é PROPERTIES OU PROPRIETES…?? veja só o codigo:


import java.io.*;
import java.util.Proprietes;

public class Ju {

	static public void main (String[] args)
	 {
	   try {
	   		java.util.Properties file = new java.util.Properties();
			file.load(new java.io.FileInputStream("arquivo.txt"));

			//agora pra usar só fazer

			System.out.prinln(file.getPropety("titulo"));
			System.out.prinln(file.getPropety("comentario"));
			System.out.prinln(file.getPropety("1"));
			System.out.prinln(file.getPropety("10"));

			//pra alterar só fazer
			file.setPropety("titulo","meuNovo Titulo");

			//ai depois q acabou de alterar... vc salva assim

			file.store(new java.io.FileOutputStream("arquivo.txt"),"Titulo"); 
	//		file.save();
			//ou é
	//		file.store();
			//ou talvez os 2 funfe....

			} catch (Exception e) {}
}
}

kra, ve o q ha de errado ai, pois parece realmente muito interessante essa parada… ah, ai vao os erros novos…

-Called Compiler C:\J2SDK1~1.1_0\bin\javac.exe-
-Target File: C:\tt\Ju.java-
C:\tt\Ju.java:2: cannot resolve symbol
symbol : class Proprietes
location: package util
import java.util.Proprietes;
^
C:\tt\Ju.java:14: cannot resolve symbol
symbol : method getPropety (java.lang.String)
location: class java.util.Properties
System.out.prinln(file.getPropety(“titulo”));
^
C:\tt\Ju.java:15: cannot resolve symbol
symbol : method getPropety (java.lang.String)
location: class java.util.Properties
System.out.prinln(file.getPropety(“comentario”));
^
C:\tt\Ju.java:16: cannot resolve symbol
symbol : method getPropety (java.lang.String)
location: class java.util.Properties
System.out.prinln(file.getPropety(“1”));
^
C:\tt\Ju.java:17: cannot resolve symbol
symbol : method getPropety (java.lang.String)
location: class java.util.Properties
System.out.prinln(file.getPropety(“10”));
^
C:\tt\Ju.java:20: cannot resolve symbol
symbol : method setPropety (java.lang.String,java.lang.String)
location: class java.util.Properties
file.setPropety(“titulo”,“meuNovo Titulo”);
^
6 errors

-Finished-

eu nem faço nocao do q seja… me ajude…

falow… valew e aguardo…

java.util.Properties file;

é assim

java.util.Properties

e pra pegar valor assim

file.getProperty(key)

vc devia usar uma IDE… (tava sem ide aki… ai fica facim de errar)

boa sorte

KRA, :smiley: blz aqui… show… deu tdo certim… e ainda incrementei e atingi meu objetivo…

agora, :?: , como q faço para deletar um nome??

seria,  :idea: , apenas entrar com um novo valor em branco, ou teria alguma opcao da pro´ria linguagem, como um delete, erase, ou algo assim??

aguardo e valews… msmo…

:lol:

bom… entenda o seguinte… essa classe java.util.Properties

ela guarda valore pra cada xave especifica…

e alem disso… pode salvar esses valores em 1 arquivo

bom…

file.getProperty(key);

busca o valor associado a xave key… onde key é uma string…

bom… pra alterar o valor pra xave… só fazer…

file.setProperty(key,“novo valor”);

ai muda o valor pra key q vc disse ali…

agora se vc quizer apagar uma key… só fazer…

file.remove(key);

quizer salvar no arquivo… tem q dar akele… file.store(…
quizer resgatar do arquivo… file.load(…

e por ai vai…

c cv fizer 193218391 alterações… e não der… file.store… quando der load denovo… vai resetar tudo… vai voltar ao valor q ta no arquivo…

ele não muda o valor diretamente no arquivo… muda sempre na classe…
só poem no arquivo quando vc da store… e tira quando vc da load…

boa sorte ai…