0

I have made this delete class of my address book program.
It gives an error when I use the renameTo() function.
Please look into my program.

import java.io.*;
import java.util.*;
class del
{

	private String stru,strf;
	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	public void calc()throws IOException
	{
		System.out.println("enter record to be deleted");
		stru=br.readLine();

		BufferedReader in=new BufferedReader(new FileReader("adbk.txt"));

		File fi=new File("tadbk.txt");

		PrintWriter p=new PrintWriter(new FileWriter("tadbk.txt",true));

		while((strf=in.readLine())!=null)
		{
			if(stru==strf)
			{
				continue;
			}
			else
			{
				p.println(strf);
			}
		}
		p.close();
		fi.renameTo("adbk.txt");//gives error here
		fi.delete();
	}
}

Please tell me how to go about it.
Thanks in advance.

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by bondo
Featured Replies
  • 2

    Here is part of description of this function, given by java help: public boolean renameTo([B]File[/B] dest) It asks a File as parameter, but you give String to it. Read More

2

Here is part of description of this function, given by java help:
public boolean renameTo(File dest)

It asks a File as parameter, but you give String to it.

Comments
Thanks a million for the help.
Helpful information =)
1

Whoops, too slow. Check out the javadocs though, it might be helpful in explaining what you need to do.

Comments
Thank you Sir,
This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.