almacal
asked on
[Java] Overwriting a line in a plain textfile with FileWriter
Hi,
Is it possible to find a line in a text file, and then overwrite that line with something else, or delete it altogether ? Here's some code
// set up file readers and writers
FileReader fRead = new FileReader("list.dat");
FileWriter fWrite = new FileWriter("list.dat",
true);
BufferedReader bIn = new BufferedReader(fRead);
BufferedWriter bOut = new BufferedWriter(fWrite);
String line, currentName;
// userName is from a html form
try {
while((line = bIn.readLine()) != null) {
StringTokenizer st = new StringTokenizer(line);
currentName = st.nextToken();
if(currentName.compareTo(u serName) == 0) {
bOut.write(userName + "Expired");
break;
}
currentName = st.nextToken() // ignore next tkn
}
catch(IOException e) {}
Am I way off base here, or what? Any help is appreciated. thanks
Alex
Is it possible to find a line in a text file, and then overwrite that line with something else, or delete it altogether ? Here's some code
// set up file readers and writers
FileReader fRead = new FileReader("list.dat");
FileWriter fWrite = new FileWriter("list.dat",
true);
BufferedReader bIn = new BufferedReader(fRead);
BufferedWriter bOut = new BufferedWriter(fWrite);
String line, currentName;
// userName is from a html form
try {
while((line = bIn.readLine()) != null) {
StringTokenizer st = new StringTokenizer(line);
currentName = st.nextToken();
if(currentName.compareTo(u
bOut.write(userName + "Expired");
break;
}
currentName = st.nextToken() // ignore next tkn
}
catch(IOException e) {}
Am I way off base here, or what? Any help is appreciated. thanks
Alex
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
almacal:
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations! No comment means you don't care.
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations! No comment means you don't care.
Recommendation: Accept mayankeagle's comment as answer. It is complete as per the questioner's needs.
ASKER