Searching Text Files Then Removing (My First Post!)
I am having a problem with deleting people from the list, to do this I was trying to make an array for every line in the file, then delete the file, and remake it excluding the name that was deleted.
But what's happening is the file is either not being deleted at all, or being remade with the same lines as before times two and another line named "null".
(I am trying to make a "friends list", I have adding and reading through the friends list already made, as you add people the text file will go down a line, then it will read through it line-by-line)
This is something like my code:
if(s1.startsWith(".dll ")){
String stn = s1.substring(5);
try{
String file = "C:/Friends.txt";
java.io.FileReader fr = new FileReader( file ) ;
java.io.BufferedReader reader = new BufferedReader( fr ) ;
String line = null ;
int xyz = 1;
String aString[];
aString = new String[100];
while( ( line = reader.readLine() ) != null )
{
aString[xyz] = line;
xyz++;
}
File bkup = new File("C:/Friends.txt");
bkup.delete();
BufferedWriter out = new BufferedWriter(new FileWriter("C:/Friends.txt", true));
for(int xxxx = 1; xxxx <= xyz; xxxx++){
if(aString[xxxx] != stn){
out.append(aString[xxxx]);
out.newLine();
}
}
out.close();
}catch(Exception e){
}