file delete and rename not working

Here is the code but it does not delete storedIp file and rename tempFile to storedIP. Both file exist

               String host=ipParsing(hostName);
               File tempFile= new File("tempFile.txt");
               File strFile = new File("StoredIp.txt");
        BufferedReader bufferReader = new BufferedReader( new FileReader(strFile));
        BufferedWriter bw = new BufferedWriter(new FileWriter(tempFile));
                String line;
        while ((line = bufferReader.readLine()) != null)   {
               tempFile.renameTo(new File ("StoredIP.txt"));


Well, a call to File.delete() does not necessary delete the file. As the JavaDoc says: be sure to check the return value.

Ignoring this (like you did) is a common source of errors.

One occasion where this delete/renameTo easily goes awry, is when the files are in use. A solution seen consists of using an additional lock file. Too complicated for such a simple thing.

Using an embedded database, like java's own Derby, which is not that difficult. The database needs no extra provision. There are good tutorials with simple example code.

Need Your Help

how to show axis in chart using jquery?

javascript jquery d3.js

I am trying to make chart using d3 library .I want to show axis in my chart .I am getting error is I add this line .call(axisn);..I try like that

Casting Class into String and vice versa in Java


I have a program in which I need to store a Class object into memory by casting it into String. Is it possible to convert the String back into the original Class so that I can use that class variab...