• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

delete a file

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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");
}
}
}
 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My first guest is that you should close the lnr and in before deleting the file
 
He's dead Jim. Grab his tricorder. I'll get his wallet and this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic