| | |
Renaming and deleting text files
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2008
Posts: 25
Reputation:
Solved Threads: 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.
Please tell me how to go about it.
Thanks in advance.
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();
}
}Thanks in advance.
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.
public boolean renameTo(File dest)
It asks a File as parameter, but you give String to it.
So what if you can see the darkest side of me?
No one would ever change this animal I have become
Help me believe it's not the real me
Somebody help me tame this animal
No one would ever change this animal I have become
Help me believe it's not the real me
Somebody help me tame this animal
http://java.sun.com/javase/6/docs/ap...(java.io.File)
Check that out. It's expecting a file, not a string. It seems like you need to create a new file with a filename of what you want to rename the file to and pass that into renameTo().
Check that out. It's expecting a file, not a string. It seems like you need to create a new file with a filename of what you want to rename the file to and pass that into renameTo().
![]() |
Similar Threads
Other Threads in the Java Forum
- Previous Thread: File ouput formatting
- Next Thread: binary search tree question
| Thread Tools | Search this Thread |
Tag cloud for Java
addressbook android api apple applet application arguments array arrays automation binary bluetooth button calculator chat class classes client code columns component converter database draw eclipse error errors event exception file fractal ftp game givemetehcodez graphics gridlayout gui helpwithhomework html ide image inetaddress input integer j2me japplet java javaprojects jme jmf jni jpanel julia link linux list loop map method methods midlethttpconnection mobile netbeans newbie number objects openjavafx oracle php print problem program programming project projects recursion rim scanner screen server set signing size smart sms socket sort sql storm string support swing test threads time tree unlimited variablebinding webservices windows





