Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

delete a file  RSS feed

 
Michael.H.Sun
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,
The following class copies the file of "app1.java" and renames the new file "WelcomeApplet3.java". However, it does not delete "app1" after copied. I wonder why? Thanks.

import java.io.*;

public class CFtest {
public static void main(String[] args) {
try {
File inputFile = new
File("c:/windows/desktop/app1.java");
File outputFile = new
File("c:/windows/desktop/WelcomeApplet3.java");
FileReader in = new FileReader(inputFile);
FileWriter out = new FileWriter(outputFile);
LineNumberReader lnr = new LineNumberReader(in);
String s;
while ( (s = lnr.readLine()) != null ) {
System.out.println(lnr.getLineNumber() + "==> " + s );
out.write(s);
}
if (inputFile.exists ())
{
inputFile.delete ();}

lnr.close();
in.close();
out.close();
}
catch (IOException ie) { System.out.println("input/output error");
}
}
}
 
Matts Smith
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My first guest is that you should close the lnr and in before deleting the file
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!