Quote:
quote:How to delete file from folder using FileOutputStream?
Please let me know ASAP
|
Okay here is some code from my program (having trouble with writing to and reading from a file but that's nothing to do with your problem :)
Code:
import java.io.*;
public class mysimpleio
{
String thefilename = "";
DataOutputStream thefileOut = null;
DataInputStream thefileIn = null;
public static void main(String[] args)
{
String text = "";
String path = "e:\\my_project\\crm\\";
if (args.length == 0)
{
System.out.println("No file name, Exiting program!");
}
if (args.length > 0)
{
for (int i=0; i < args.length; i++)
text = text + args[i];
System.out.print (path);
File fileOut = new File (path,text);
fileOut.createNewFile();
DataOutputStream thefileOut = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(fileOut)));
try
{
if (fileOut.exists())
fileOut.delete();
}
catch(IOException e)
{
System.out.print("Error occured!"+ e);
}
it is the TRY bit ~10 lines up that's important to you!!
I've put in the code down to the end of the TRY block so you can see what i've done and how it relates to the fileOut.delete() action.
HTH
dave.