| | |
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 add android api applet application array automation bank bi binary blackberry block bluetooth class client code compile compiler component database developmenthelp dice eclipse equation error event fractal functiontesting game gameprogramming givemetehcodez graphics gui health html hyper ide idea image infinite int j2me j2seprojects java javac javame javaprojects jetbrains jni jpanel jtable julia learningresources lego linux mac main map method mobile myregfun netbeans notdisplaying number online openjavafx pearl problem program project qt scanner screen scrollbar server set singleton sms sort sorting spamblocker sql sqlserver storm string superclass swing system textfields thread threads time title tree tutorial-sample update variablebinding windows xor





