| | |
Renaming and deleting text files
![]() |
•
•
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 |
-xlint android api applet application array arrays automation bi binary blackberry block bluetooth chat class client code compile compiler component database developmenthelp eclipse error fractal freeze functiontesting game gameprogramming givemetehcodez graphics gui health html ide image input int integer j2me j2seprojects java javac javaprojects jetbrains jni jpanel jtable julia learningresources lego linux list login loop loops mac main map method methods mobile myregfun netbeans newbie nonstatic notdisplaying number online pearl problem program programming project qt recursion scanner screen server set singleton sms sort spamblocker sql string swing system textfields thread threads time title tree tutorial-sample update variablebinding windows working xor





