Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 5th, 2007, 02:02 AM
Authorized User
 
Join Date: Sep 2006
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default Delete file from folder using FileOutputStream

Hi
This is Kotaiah,

How to delete file from folder using FileOutputStream?

Please let me know ASAP

Thanks&Regards
Kotaiah.Katragadda
no:91+9960526079
L&T Infotech,Pune

 
Old March 8th, 2007, 04:47 AM
Authorized User
 
Join Date: Feb 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to delete file System.IO.Delete error maricar C# 13 March 14th, 2014 06:50 AM
How to delete folder with php tinhbanghuu PHP How-To 4 March 26th, 2008 02:59 AM
Can Global.asa be used to delete a folder. solos Classic ASP Basics 9 February 13th, 2007 06:05 PM
Rename File/Folder shivanshub General .NET 0 August 11th, 2006 01:57 PM
JSP file upload and delete file pandjie JSP Basics 0 January 29th, 2005 10:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.